Search code examples
react-nativereact-reduxreact-navigationreact-native-navigationreact-navigation-stack

which one to use between navigation.navigate vs navigation.push under which conditions?


I know how navigation.navigate and navigation.push work in react-native.

But I was wondering which is best to use under which conditions? I have been through their documentation react navigation but can't get it clearly.

Thank you!!!


Solution

  • You use navigate when you want to navigate between screens. When you are in a screen and you try to navigate to this screen again then nothing is happening because you are already there.

    Using push you can add a new screen on the stack dynamically, it's useful when you want to pass unique data each time calling the same screen.

    Have a look here for more details and an example https://reactnavigation.org/docs/navigating/

    I hope it helps