Answers for "get params navigation react native"

0

react native use route params

import * as React from 'react';
import { Text } from 'react-native';
import { useRoute } from '@react-navigation/native';

function MyText() {
  const route = useRoute();

  return <Text>{route.params.caption}</Text>;
}
Posted by: Guest on June-30-2021
0

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.
Posted by: Guest on January-07-2022

Code answers related to "get params navigation react native"

Code answers related to "Javascript"

Browse Popular Code Answers by Language