What does merge do in navigation.navigate (React Native)?

Viewed 1931

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/

1 Answers

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

Related