Does The Value In This.setState({value:true;}) Be Available Even After Navigating Across Pages

- 1 answer

This is in regard to React-Native in particular, but, its the same in ReactJS as well I guess, so any answers would be great.

If I set a state in Page 1, say-


If I navigate to another scene/page, say Page 2 using the Navigator component. And say I come back or in later point of time navigate back to Page 1, Can I still be able to access-


I am not able to get to this stage as well. So, wanted to know if its possible. If not, how do I persist some properties of that page(say checkbox values, radio buttons values, some True/False flags etc.,) Is AsyncStorage the only other way?

Adding more thoughts:

This.prop would be more like a property that we have to pass as parameters to child modules right? But, what I need is - data to persist in the current page. Giving an example - An applist implementation(in case of react native) Android. Only when we launch the applist screen I want to see the applist and its data.



Yes the state remains for the page as long as you don't reinitialize the page. Meaning you can't call the same page again farther down in the navigation and expect it to keep it's state. You would then need to use this.prop.

I see a couple of issues. To set the state you do it like this: this.setState({foo: true});

Then you can see the result here:

if ( { // <-- you were calling value() as a function...
} else {