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
{{ message }}
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
I've noticed that for some reason navigationOptions aren't set correctly when using useEffect to initialize them when component mounts.
Here's a basic test scenario to reproduce this:
functionTestScreen(){constnavigation=useNavigation();useEffect(()=>{console.log('component did mount');navigation.setParams({test: true,});},[]);returnnull;}TestScreen.navigationOptions=(screenProps)=>{console.log('navigationOptions',screenProps.navigation.state.params);};
When this screen gets navigated to, here's what I see in logs:
navigationOptions undefined
component did mount
navigationOptions {test: true}
navigationOptions undefined
Shouldn't it be:
navigationOptions undefined
component did mount
navigationOptions {test: true}
I've also noticed that output is correct when I wrap navigation.setParams in setTimeout:
According to the code, I don't feel like it's related to hooks but rather related to react navigation core. Can you see if it works better without hooks?
I suspect setting params synchronously just after render makes something weird happen. As it triggers a re-render and we are still mounting the screen, the navigation options might be computed twice, because the screen has to render twice during the render phase.
But why do you want to set a param synchronously in useEffect in the first place, instead of using the navigation options? What's the usecase for this? This will only lead to unnecessary double-render on mount, while setting directly test: true param in navigation options would prevent it.
I've noticed that for some reason navigationOptions aren't set correctly when using useEffect to initialize them when component mounts.
Here's a basic test scenario to reproduce this:
When this screen gets navigated to, here's what I see in logs:
Shouldn't it be:
I've also noticed that output is correct when I wrap
navigation.setParams
insetTimeout
:The text was updated successfully, but these errors were encountered: