Skip to content

Instantly share code, notes, and snippets.

@HenriqueLimas
Last active April 13, 2017 03:02
Show Gist options
  • Select an option

  • Save HenriqueLimas/fd719392d0747943fb2842d15ff2ebf0 to your computer and use it in GitHub Desktop.

Select an option

Save HenriqueLimas/fd719392d0747943fb2842d15ff2ebf0 to your computer and use it in GitHub Desktop.

Redux overview

Start using React and use Redux only when you need. Its not so difficult to refact to redux. It can complicate your app. Its difficult to understand. Central repository for all your state.

Its hard to components comunicate with each other, so redux comes to help.

It make a hard dependency on it.

Redux overkill things.

Reducers

Reducers is the function that we pass on the reduce method of arrays. It take a state and an action and it returns a new state.

Stores

Store needs to be simple, maybe just add middlewares.

Actions & action creators

Separte this into pieces.

Use Object.assign to return a new object merging the old state with new properties.

React on the app

React-redux is a tiny library to facilitate things and use redux on react.

using connect function to connect the components with redux. We can pass a function to map all the properties to the components.

Dispatching actions with redux

We can also pass methods that dispatch things.

Dispatch take an action and pass it to a reducer.

Redux review

action -> dispatch -> reducer

The provider incorporates and it has a subscription function that call the forceUpdate from react.

With mapDispatchToProps you can reduce the dependencie with redux.

Search Submit event

React has also a context. But try to not use it. Its available everywhere inside your app. Its similar to redux, so use it instead of context. It mades difficult to debug issues. If you don't put contextTypes it doesn't show on the context.

React-router use context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment