Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vonovak/ef72f5efe1d36742de8968ff6a708985 to your computer and use it in GitHub Desktop.
Save vonovak/ef72f5efe1d36742de8968ff6a708985 to your computer and use it in GitHub Desktop.
key behavior in react-navigation v1.x.x

v1 behavior

In v1, key parameter is used as an identifier for the route to navigate to. If you provide the identifier (as for example in navigate({ routeName: 'someScreen', params: { someParam: 'someValue' }, key: 'someScreen' })) and user triggers such navigation action twice (eg. by pushing a button that calls the navigation action quickly twice in a row), the navigation action will be executed only once. The second call to navigate finds out that the route with the key is already present on the stack and instead of pushing a new instance of the same route, it calls setParams on the existing one.

Without using the key, calling navigate({ routeName: 'someScreen' }) twice would result in pushing the route onto the stack two times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment