Do you have a full example how to use this? I have a codebase I'm trying to refactor to use this. This is my current setup. Let me know your thoughts please.
const { getStateForAction } = AppNavigation.router;
const initialState = getStateForAction(NavigationActions.init);
const getCurrentRouteName = (navState) => {
if (Object.prototype.hasOwnProperty.call(navState, 'index')) {
return getCurrentRouteName(navState.routes[navState.index]);
}
return navState.routeName;
};
const generateNavigationAction = (state, routeName, params = {}) => {
// Don't navigate to the same screen if is already there.
if (getCurrentRouteName(state) === routeName) {
return state;
}
const nextState = getStateForAction(
NavigationActions.navigate({
routeName,
params
}),
state
);
return nextState || state;
};
// redux-action
export default handleActions(
{
// Custom actions types
[CHAT_MAIN]: state => generateNavigationAction(state, CHAT_MAIN),
}, initialState);
Class AppWithNavigationStateObject extends React.PureComponent {
render(): React.Node {
const { dispatch, [NAME]: state } = this.props;
return <AppNavigation navigation={addNavigationHelpers({ dispatch, state, addListener })} />;
}
}
AppWithNavigationStateObject.propTypes = {
dispatch: PropTypes.func.isRequired,
[NAME]: PropTypes.object.isRequired
};
const AppWithNavigation = connect(state => ({
[NAME]: state[NAME]
}))(codePush(codePushOptions)(AppWithNavigationStateObject));
const AppWithNavigationState = createReactNavigationReduxMiddleware(AppWithNavigation);
export { AppWithNavigationState };
}