Skip to content

Instantly share code, notes, and snippets.

@Landerson352
Last active September 16, 2019 04:10
Show Gist options
  • Save Landerson352/da316c1b8bcbd48249b34e5fea7e9824 to your computer and use it in GitHub Desktop.
Save Landerson352/da316c1b8bcbd48249b34e5fea7e9824 to your computer and use it in GitHub Desktop.
A hook for accessing the react-navigation prop.
import { useContext } from 'react';
import { NavigationContext } from 'react-navigation';
import { get } from 'lodash';
import ROUTE from '../route';
const useNavigation = () => {
const navigation = useContext(NavigationContext);
const routeName = get(navigation, 'state.routeName');
const route = ROUTE[routeName];
return [navigation, route];
};
export default useNavigation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment