UNPKG

788 BJavaScriptView Raw
1import * as React from 'react';
2import NavigationContainerRefContext from './NavigationContainerRefContext';
3import NavigationContext from './NavigationContext';
4
5/**
6 * Hook to access the navigation prop of the parent screen anywhere.
7 *
8 * @returns Navigation prop of the parent screen.
9 */
10export default function useNavigation() {
11 const root = React.useContext(NavigationContainerRefContext);
12 const navigation = React.useContext(NavigationContext);
13
14 if (navigation === undefined && root === undefined) {
15 throw new Error("Couldn't find a navigation object. Is your component inside NavigationContainer?");
16 } // FIXME: Figure out a better way to do this
17
18
19 return navigation !== null && navigation !== void 0 ? navigation : root;
20}
21//# sourceMappingURL=useNavigation.js.map
\No newline at end of file