Answer the question
In order to leave comments, you need to log in
Why is Ref.current null/undef when passing Ref in child components?
I'm trying to pass the active screen to a child screen to stop a function in the child screen if active screen !== to the child screen using the following code:
const Drawer = createDrawerNavigator();
function App() {
const routeNameRef = createRef();
const navigationRef = useNavigationContainerRef();
return (
<Context.Provider value={getCurrentRouteName}>
<NavigationContainer ref={navigationRef}
onReady={() => {
routeNameRef.current = navigationRef.getCurrentRoute().name;
}}
onStateChange={async () => {
const currentRouteName = navigationRef.getCurrentRoute().name;
routeNameRef.current = currentRouteName;
}}>
<Drawer.Navigator>
<Drawer.Screen name="Home" component={Home}
initialParams={{routeNameRef}}}/>
<Drawer.Screen name="Favorite" component={Favorite}/>
</Drawer.Navigator>
<Footer/>
</NavigationContainer>
</Context.Provider>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question