You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
4.6 KiB

{"ast":null,"code":"import { getActionFromState, getStateFromPath, NavigationContainerRefContext } from '@react-navigation/core';\nimport * as React from 'react';\nimport LinkingContext from \"./LinkingContext\";\nexport default function useLinkTo() {\n var navigation = React.useContext(NavigationContainerRefContext);\n var linking = React.useContext(LinkingContext);\n var linkTo = React.useCallback(function (to) {\n if (navigation === undefined) {\n throw new Error(\"Couldn't find a navigation object. Is your component inside NavigationContainer?\");\n }\n if (typeof to !== 'string') {\n navigation.navigate(to.screen, to.params);\n return;\n }\n if (!to.startsWith('/')) {\n throw new Error(\"The path must start with '/' (\" + to + \").\");\n }\n var options = linking.options;\n var state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(to, options.config) : getStateFromPath(to, options === null || options === void 0 ? void 0 : options.config);\n if (state) {\n var action = getActionFromState(state, options === null || options === void 0 ? void 0 : options.config);\n if (action !== undefined) {\n navigation.dispatch(action);\n } else {\n navigation.reset(state);\n }\n } else {\n throw new Error('Failed to parse the path to a navigation state.');\n }\n }, [linking, navigation]);\n return linkTo;\n}","map":{"version":3,"sources":["useLinkTo.tsx"],"names":["getActionFromState","getStateFromPath","NavigationContainerRefContext","React","LinkingContext","useLinkTo","navigation","useContext","linking","linkTo","useCallback","to","undefined","Error","navigate","screen","params","startsWith","options","state","config","action","dispatch","reset"],"mappings":"AAAA,SACEA,kBAAkB,EAClBC,gBAAgB,EAChBC,6BAA6B,QACxB,wBAAwB;AAC/B,OAAO,KAAKC,KAAK,MAAM,OAAO;AAE9B,OAAOC,cAAc;AAiBrB,eAAe,SAASC,SAAS,GAE7B;EACF,IAAMC,UAAU,GAAGH,KAAK,CAACI,UAAU,CAACL,6BAA6B,CAAC;EAClE,IAAMM,OAAO,GAAGL,KAAK,CAACI,UAAU,CAACH,cAAc,CAAC;EAEhD,IAAMK,MAAM,GAAGN,KAAK,CAACO,WAAW,CAC7BC,UAAAA,EAAiB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FromPath, NavigationContainerRefContext } from '@react-navigation/core';\nimport * as React from 'react';\nimport LinkingContext from './LinkingContext';\nexport default function useLinkTo() {\n const navigation = React.useContext(NavigationContainerRefContext);\n const linking = React.useContext(LinkingContext);\n const linkTo = React.useCallback(to => {\n if (navigation === undefined) {\n throw new Error(\"Couldn't find a navigation object. Is your component inside NavigationContainer?\");\n }\n if (typeof to !== 'string') {\n // @ts-expect-error: This is fine\n navigation.navigate(to.screen, to.params);\n return;\n }\n if (!to.startsWith('/')) {\n throw new Error(`The path must start with '/' (${to}).`);\n }\n const {\n options\n } = linking;\n const state = options !== null && options !== void 0 && options.getStateFromPath ? options.getStateFromPath(to, options.config) : getStateFromPath(to, options === null || options === void 0 ? void 0 : options.config);\n if (state) {\n const action = getActionFromState(state, options === null || options === void 0 ? void 0 : options.config);\n if (action !== undefined) {\n navigation.dispatch(action);\n } else {\n navigation.reset(state);\n }\n } else {\n throw new Error('Failed to parse the path to a navigation state.');\n }\n }, [linking, navigation]);\n return linkTo;\n}\n//# sourceMappingURL=useLinkTo.js.map"]},"metadata":{},"sourceType":"module"}