question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to reset Navigation states ?

See original GitHub issue

I want to mimic ReactNavigation switch navigator behavior that resets the routes to the default states after navigating away from it (for example after the user logs in/out). How can I do that ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SatyaFarizcommented, May 16, 2019

It works! I’ll close this for now. Thanks for the quick reply!!!

0reactions
grahammendickcommented, May 16, 2019

Ahh, thanks for providing a more detailed explanation. I understand exactly what you mean now.

I suggest you add a React key prop to your MainScreen component. If React detects that the key has changed then it will clear all the state from the component tree, for example, the selected tab.

main.renderScene = ({clear = false}) => <MainScreen key={clear ? '1' : '0'}/>

After the sign in process is finished, when you navigate to the MainScreen pass a different clear value to reset the MainScreen

stateNavigator.navigate('main', {clear: true});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I reset a screens state to its initial state when using ...
I want to reset the state (back to initial state) in a functional component when navigated via navigation.navigate() .
Read more >
React Navigation re-render / reset previous page's state on ...
React Navigation re-render / reset previous page's state on navigation or goBack ... TimeSaver: (If you understand the title, go to the SOLUTION:...
Read more >
CommonActions reference - React Navigation
The reset action allows to reset the navigation state to the given state. It takes the following arguments: ... The state object specified...
Read more >
reset navigation state crashes on Android #10148 - GitHub
I want to reset navigation state and navigate the user to the SignInScreen when user press the Logout button in the ProfileScreen ....
Read more >
How to use the react-navigation.NavigationActions.reset ...
setState({ pwd: stringToU8("000000000000000000000000") }); // Removing it's refs do the GC can clean it delete this.state.pwd; // Construct a reset action for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found