Skip to content

Instantly share code, notes, and snippets.

@williesmithchen
Created January 21, 2021 04:40
Show Gist options
  • Save williesmithchen/0f29e0e81b65d5d06827ffa4ad31deab to your computer and use it in GitHub Desktop.
Save williesmithchen/0f29e0e81b65d5d06827ffa4ad31deab to your computer and use it in GitHub Desktop.
useParentStackNavigator with react-navigationv5
import React from 'react';
import { useNavigation } from '@react-navigation/native';
const useParentStackNavigator = props => {
const navigation = useNavigation();
// loop for getStackNavigator(dangerouslyGetParent)
const getStackNavigator = React.useCallback(_navigation => {
return _navigation.dangerouslyGetParent()
? getStackNavigator(_navigation.dangerouslyGetParent())
: _navigation;
}, []);
const parentStackNavigator = getStackNavigator(navigation);
return parentStackNavigator;
};
export default useParentStackNavigator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment