Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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/

like image 822
user3508953 Avatar asked Apr 30 '21 02:04

user3508953


People also ask

How do you navigate in stack Navigator?

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.

How does navigation work in React Native?

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.


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

like image 82
keysl Avatar answered Sep 30 '22 19:09

keysl