Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react native getting old navigation parameter

The problem here is how navigation.navigate works. If you use it without
passing the key for the next screen, react-navigation won't match it with the 
screen that is already mounted hence mounting another one.

What you can observe here is exactly the case when the component was not yet 
unmounted but navigate doesn't know that and renders another instance of the 
same component.

You can prevent this by passing the key param into navigate function as follows:

navigation.navigate({name: 'ScreenB', key: 'ScreenB', params: { id: 1}})

navigation.navigate({name: 'ScreenB', key: 'ScreenB', params: { id: 2}})

Now StackNavigator can check if screen with the same key already exists and 
prevent it from mounting.
 
PREVIOUS NEXT
Tagged: #react #native #navigation #parameter
ADD COMMENT
Topic
Name
7+7 =