Code Monkey home page Code Monkey logo

react-navigation-redux-utils's People

react-navigation-redux-utils's Issues

Usage Example with Redux

Hi,

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.

I'm struggling migrating from react-navigation v1 (entire navigation state managed in redux) to v3. The react-navigation-redux-helpers doesnt help much. I'm wondering whether I can get some help. Otherwise, any thought on how to eliminate redux and use the navigator directly?

Screenshot 2019-08-04 at 21 16 58

My code looks like so currently:


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 };

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.