I would like to use Redux for React Native. Currently I have no set data management, so the index.ios.js has the following:
renderScene(route, navigator){
this._navigator = navigator
return (
<route.component navigator={navigator} {...route.passProps}/>
)
}
<Navigator
configureScene={this.configureScene}
initialRoute={{name: 'Login', component: Login}}
renderScene={(route, navigator) => this.renderScene(route, navigator)}
style={styles.container}
navigationBar={
<Navigator.NavigationBar
style={styles.navBar}
routeMapper={NavigationBarRouteMapper}
/>
}
/>
I am planning to switch to Redux. With my current set up, not using any frameworks, only exception being react-router, what would be the most preferred way to navigate using Redux? A sample using store, reducers, and actions would be extremely helpful.
EDIT: react-navigation should be used now instead of NavigationExperimental.
--
I advise you use NavigationExperimental instead of Navigator. The last is depreciated. There is an example in the RN documentation, right here. It uses simple reducers to manage your navigation state. But you can also handle this state with Redux since it is the same logic.
This is my setup with tabs, using Redux and NavigationExperimental:
navigator.js (note: the renderOverlay prop in CardStack will be renamed renderHeader in 0.32)
actions.js
reducer.js (note: I use immutable here, but it's up to you to use whatever fit you)
Finally, in MyScene.js component you can simply handle the component to show by testing the current route (with a switch for example). By passing the navigate function in your components, you can manage your scenes (ie: this.props.navigate({ type: 'push', route: { key: 'search' } })).
Notice that you can handle your state and your actions as you wish. The main idea to understand is how the state is reduced, regardless you use redux or not.
I suggest you use react-navigation for native and web environment it will replace NavigationExperimental just take a look the following example.
Just define your navigation in your app.
...and navigate
And do the following in order to add redux just define your reducer...
...and navigate in your component with
addNavigationHelpers