UNPKG

1.45 kBSource Map (JSON)View Raw
1{"version":3,"names":["useNavigation","root","React","useContext","NavigationContainerRefContext","navigation","NavigationContext","undefined","Error"],"sources":["useNavigation.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport NavigationContainerRefContext from './NavigationContainerRefContext';\nimport NavigationContext from './NavigationContext';\nimport type { NavigationProp } from './types';\n\n/**\n * Hook to access the navigation prop of the parent screen anywhere.\n *\n * @returns Navigation prop of the parent screen.\n */\nexport default function useNavigation<\n T = NavigationProp<ReactNavigation.RootParamList>\n>(): T {\n const root = React.useContext(NavigationContainerRefContext);\n const navigation = React.useContext(NavigationContext);\n\n if (navigation === undefined && root === undefined) {\n throw new Error(\n \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n );\n }\n\n // FIXME: Figure out a better way to do this\n return (navigation ?? root) as unknown as T;\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;;;;;;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAT,GAER;EACL,MAAMC,IAAI,GAAGC,KAAK,CAACC,UAAN,CAAiBC,sCAAjB,CAAb;EACA,MAAMC,UAAU,GAAGH,KAAK,CAACC,UAAN,CAAiBG,0BAAjB,CAAnB;;EAEA,IAAID,UAAU,KAAKE,SAAf,IAA4BN,IAAI,KAAKM,SAAzC,EAAoD;IAClD,MAAM,IAAIC,KAAJ,CACJ,kFADI,CAAN;EAGD,CARI,CAUL;;;EACA,OAAQH,UAAR,aAAQA,UAAR,cAAQA,UAAR,GAAsBJ,IAAtB;AACD"}
\No newline at end of file