Skip to content

Commit f98a1dc

Browse files
committed
Update Redux Integration docs for react-navigation-redux-helpers@2.0.0
1 parent 30d761d commit f98a1dc

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

docs/redux-integration.md

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Some folks like to have their navigation state stored in the same place as the r
1010

1111
## Overview
1212

13-
1. To handle your app's navigation state in Redux, you can pass your own [`navigation`](navigation-prop.html) prop to a navigator. This `navigation` prop is an object that must contain the navigation [`state`](navigation-prop.html#state-the-screen-s-current-state-route), [`dispatch`](navigation-prop.html#dispatch-send-an-action-to-the-router), and `addListener` properties.
13+
1. To handle your app's navigation state in Redux, you can pass your own [`navigation`](navigation-prop.html) prop to a navigator. This `navigation` prop is an object that must contain the navigation [`state`](navigation-prop.html#state-the-screen-s-current-state-route), [`dispatch`](navigation-prop.html#dispatch-send-an-action-to-the-router), and `addListener` properties. `react-navigation-redux-helpers` handles this for your behind the scenes with a HOC called `reduxifyNavigator` that takes your navigation state and a dispatch function as props, and constructs a custom `navigation` prop.
1414

1515
2. The aforementioned navigation `state` will need to be kept updated using React Navigation's navigation reducer. You will call this reducer from your Redux master reducer.
1616

@@ -46,10 +46,9 @@ import {
4646
combineReducers,
4747
} from 'redux';
4848
import {
49-
createNavigationPropConstructor, // handles #1 above
50-
createNavigationReducer, // handles #2 above
51-
createReactNavigationReduxMiddleware, // handles #4 above
52-
initializeListeners, // handles #4 above
49+
createNavigationReducer,
50+
reduxifyNavigator,
51+
createReactNavigationReduxMiddleware,
5352
} from 'react-navigation-redux-helpers';
5453
import { Provider, connect } from 'react-redux';
5554
import React from 'react';
@@ -62,34 +61,16 @@ const appReducer = combineReducers({
6261
...
6362
});
6463

65-
// Note: createReactNavigationReduxMiddleware must be run before createNavigationPropConstructor
64+
// Note: createReactNavigationReduxMiddleware must be run before reduxifyNavigator
6665
const middleware = createReactNavigationReduxMiddleware(
6766
"root",
6867
state => state.nav,
6968
);
70-
const navigationPropConstructor = createNavigationPropConstructor("root");
71-
72-
class App extends React.Component {
73-
componentDidMount() {
74-
initializeListeners("root", this.props.nav);
75-
}
76-
77-
render() {
78-
this._navigation = navigationPropConstructor(
79-
this.props.dispatch,
80-
this.props.nav,
81-
AppNavigator.router,
82-
() => this._navigation
83-
);
84-
return <AppNavigator navigation={this._navigation} />;
85-
}
86-
87-
}
8869

70+
const App = reduxifyNavigator(AppNavigator, "root");
8971
const mapStateToProps = (state) => ({
90-
nav: state.nav,
72+
state: state.nav,
9173
});
92-
9374
const AppWithNavigationState = connect(mapStateToProps)(App);
9475

9576
const store = createStore(

0 commit comments

Comments
 (0)