In 'react-navigation' library, How can I send the parameters with initialRouteName in Stack.Navigator.
return (
<Stack.Navigator
initialRouteName={routeName}
screenOptions={{
animation: 'slide_from_right',
}}>
This is the return of my navigation file and I'm setting the routeName dynamically but the screen on which I want to initially route must need route parameters to pass.
CodePudding user response:
you can utilize the prop "initialParams" that can be added to your screen component
<Screen
initialParams={{id:0}}
{...otherScreenProps}
/>
you can also handle it with a condition like initialParams={initialRouteName === screenName ? {id:0} : undefined}
I believe there are other options like setParams, but i'm unsure of your exact use case
CodePudding user response:
you can pass params as below.
initialParams={{ itemId: 42 }}
These initialParams
props are provided by react-navigation, you can use that initially.
also whenever you setparams from the specific screen you can use the code below.
navigation.setParams({
itemId: {set your dynamic value},
});
for the reference :- click here