Code Monkey home page Code Monkey logo

react-router4-redux-example's Introduction

Deprecated

React Router's API changed between the v4 alphas and the release version, making this code irrelevant. If you're looking for Redux-React Router v4 bindings I recommend checking out Connected React Router.


An example for illustrating a possible technical direction for integrating Redux & React Router v4.

Differences

The modified version of react-router-redux is in src/react-router-redux/. The differences are in reducer.js and sync.js.

reducer.js

reducer.js exports a factory function createReducer that takes history. The reducer needs access to the history instance so it can set its initial state properly.

sync.js

Syncing the store with the history is now much simpler thanks to a one-way flow of state. It has an order of magnitude less code (~10 lines vs ~100 lines), and there's no more internal state. We simply subscribe to the history and dispatch an action to the store with the given location and action.

Dev Instrumentation

I've instrumented the app with a few handy hooks for playing with the app state:

  • dispatch - the store's dispatch is available globally as dispatch
  • Router redux actions - the router redux action creators (push, replace, go, goBack, & goForward) are available globally. Try something like dispatch(push('/bar')) or dispatch(goBack()).
  • history - the history instance is available globally as h. Try something like h.push('/foo').
  • Redux Dev Tools - the store is instrumented to dev tools so you can play around with time travel debugging

react-router4-redux-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.