You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I navigate from from a screen within the root stack ("RootScreen") to a screen within the nested stack ("NestedStack").
Check the route.state of this stack. Use any method: getState, useNavigationState, the route prop all give the same result.
constNestedNavigator=({ route })=>{constcurrentRoute=useNavigationState((state)=>state.routes.find((route)=>route.name==='NestedStack'));return(<>// undefined<Text>Routestateindex: {route?.state?.index}</Text>// also undefined<Text>Routestateindex: {currentRoute?.state?.index}</Text><NestedStack.Navigator><NestedStack.Screencomponent={NestedScreen1}name="NestedScreen1"/><NestedStack.Screencomponent={NestedScreen2}name="NestedScreen2"/></NestedStack.Navigator></>);};
To get access to the state property I have to perform any navigation action within the nested stack.
Expected behavior
The nested stack is rendered and so is a screen within the stack.
The state property containing the name and index of the currently rendered route should already be accessible.
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.
"The route prop passed to components often contained a state property which held state of the child navigator. While it wasn't meant to be public and we recommended against using it in the docs, we've seen a lot of people use this property.
It's problematic to use the property since it's not guaranteed to exist before navigation happens in the child navigator. This can cause subtle bugs in your app which you might not notice during development. So we have started warning on using this property in React Navigation 5 and removed this property entirely in React Navigation 6 prevent its usage."
Although this is not exactly the same case (I don't intend to use the route prop at all), this shows that this probably doesn't work by design.
I haven't found a solution.
I'd really appreciate any advice.
Current behavior
Expected behavior
The nested stack is rendered and so is a screen within the stack.
The state property containing the name and index of the currently rendered route should already be accessible.
Reproduction
https://snack.expo.dev/WDITwptdY68Ahe_pf0wwW
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: