Jim
Jim

Reputation: 2312

What are the benefits of using redux to manage navigation state?

If you're using a nav library such as react-navigation for instance, what's the point of going through the trouble of using redux to also manage the navigation state if react-navigation already manages it? It seems like it necessarily over-complicates setup.

for instance, navigating screens looks like more of a pain:

navigate = () => {
  const navigateScreens = NavigationActions.navigate({
    routeName: "OtherScreen",
    params: {someProperty: "someValue"}
  })
  this.props.navigation.dispatch(navigateScreens);
}:

instead of just react-navigation's:

this.props.navigation.navigate("OtherScreen")

ReactNavigation docs say specifically: "Can I store the navigation state in Redux too? This is technically possible, but we don't recommend it - it's too easy to shoot yourself in the foot and slow down / break your app. We encourage you to leave it up to React Navigation to manage the navigation state."

So there must be some massive benefit to going through all that extra...right? What are some practical use-cases/scenarios of redux managing navigation-state and that are worth this trade-off and disregarding react-nav docs?

Upvotes: 0

Views: 216

Answers (2)

Rishav Kumar
Rishav Kumar

Reputation: 5450

Apart from maintaining the history record or back button android functionality storing navigation state in redux does no good!

Also if you want to know the screens where the users have been to and from which screen navigation happened you can use the redux nav state.

Upvotes: 0

Symphony0084
Symphony0084

Reputation: 1435

It probably is not worth implementing just for managing routes alone. If you have lots of global data and a big component tree, the Redux setup is very worth it. However if you’re just trying to manage one or even a few data points, you are probably better off with a simpler strategy of manually passing props through the tree.

Upvotes: 2

Related Questions