Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React + Redux + React Navigation 2.0: connect() or withNavigation() first?

Couldn't find it in the docs: What is the best practice when using React Navigation together with Redux?

Should you do 1.:

export default withNavigation(connect(
  mapStateToProps, 
  { someFunction }
)(SomeComponent))

Or 2.:

export default connect(
  mapStateToProps, 
  { someFunction }
)(withNavigation(SomeComponent))

?

like image 467
J. Hesters Avatar asked Jul 23 '18 18:07

J. Hesters


People also ask

How do you use navigation in react Redux?

To handle your app's navigation state in Redux, you can pass your own navigation prop to a navigator. Once you pass your own navigation prop to the navigator, the default navigation prop gets destroyed. You must construct your own navigation prop with state , dispatch , and addListener properties.

Why react navigation is not working?

This can happen if you are passing non-serializable values such as class instances, functions etc. in params. React Navigation warns you in this case because this can break other functionality such state persistence, deep linking etc.


1 Answers

After some googling it seems to be that 1. is the best practice.

like image 114
J. Hesters Avatar answered Oct 07 '22 16:10

J. Hesters