I don't understand what merge
does in navigation.navigate
navigation.navigate({
name: 'Home',
params: { post: postText },
merge: true,
});
Code reference is taken from https://reactnavigation.org/docs/params/
navigate If the screen is not present, it'll push a new screen. For example, if you have a stack with the history Home > Profile > Settings and you call navigate(Profile) , the resulting screens will be Home > Profile as it goes back to Profile and removes the Settings screen.
React Navigation is built with JavaScript and lets you create components and navigation patterns that look and feel like truly native ones. React Navigation uses what's called a stack navigator to manage the navigation history and presentation of the appropriate screen based on the route taken by a user inside the app.
Imagine you are on a route or screen called BlogPage
with the following params
{ title: 'A title', author: 'keysl' }
and you navigate into different Blog post using
navigation.navigate({
name: 'BlogPage',
params: { title: 'B title' },
});
So prior to Navigation 5 the default was to merge this, so the code above will produce a page with params like
{
title: 'B title',
author: 'keysl' // note that keysl is not passed at the code below
}
This was not ideal and prone to confusion. So, the React Navigation team removed this default. Though it's useful in different cases.
Now in order to replicate the functionality above the merge:true
was introduced.
I can't find the migration statement but that's the gist of what it does
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With