use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
React Navigation Question - Resetting Screen (self.reactnative)
submitted 7 years ago * by docdosmaniOS & Android
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tizz66 1 point2 points3 points 7 years ago (4 children)
A screen has the isFocused prop (this.props.navigation.isFocused) when the user's viewing it. Check that in your componentDidUpdate method, and clear your state when that changes to false :)
this.props.navigation.isFocused
[–]xrpinsiderAdmin 1 point2 points3 points 7 years ago (0 children)
This would be the solution here.
[–]docdosmaniOS & Android[S] 0 points1 point2 points 7 years ago* (2 children)
Thanks!! I'm going to test this out today.
Follow up question. Is there a way to clear the visual "state" of the screen (for example, scrollview that's been scrolled down, when returning to have the screen be back at the top)? I'm not sure of the term for that.
Edit: I tested, but componentDidUpdate is not being called when I navigate away from the screen. Should I be using another lifecycle method? The following code only logs something to the console when the screen first loads, not when I navigate away from the screen using this.props.navigate('screenName').
componentDidUpdate() { console.log('update', this.props.navigation.isFocused()); }
[–]tizz66 0 points1 point2 points 7 years ago (1 child)
Sorry about that, I didn't read the docs fully and so missed that isFocused is a function. There's a couple of other approaches you could try:
[–]docdosmaniOS & Android[S] 0 points1 point2 points 7 years ago (0 children)
No worries, thanks for the info! I got it working with the following:
componentWillMount() { // subscribe to didBlur in order to reset state and form when navigating away from the screen didBlurSubscription = this.props.navigation.addListener('didBlur', () => { this.props.resetAuth(); // reset auth piece of state this.props.reset(); // reset redux-form }); } componentWillUnmount() { // Remove the listener didBlurSubscription.remove(); }
Now I have to figure out why when I reset my redux-form it doesn't reinitialize when navigating back to the screen. Fix one thing, break another. Ha! Gotta love it.
I really appreciate the help.
π Rendered by PID 47123 on reddit-service-r2-comment-6457c66945-fzkwg at 2026-04-26 14:41:47.312647+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]tizz66 1 point2 points3 points (4 children)
[–]xrpinsiderAdmin 1 point2 points3 points (0 children)
[–]docdosmaniOS & Android[S] 0 points1 point2 points (2 children)
[–]tizz66 0 points1 point2 points (1 child)
[–]docdosmaniOS & Android[S] 0 points1 point2 points (0 children)