React Redux — Map State and Actions to Props

December 29, 2016 0 Comments by

Two methods you will often see in React Redux applications. Provide access to your state and actions as props in your components.


mapStateToProps(state): function to map the state provided by the done action to props in your component;


mapActionsToProps(actions): function to map the actions to props in your component; Currently, only the done action exists and is used when you are finished fetching props.


https://react.jsnews.io/server-side-rendering-library-for-react-router-v4-and-webpack-2-reactjs-reactrouter-webpack-javascript/


bindActionCreators()

bindActionCreators(actionCreators, dispatch). Turns an object whose values are action creators, into an object with the same keys, but with every action creator ...

The only use case for bindActionCreators is when you want to pass some action creators down to a component that isn't aware of Redux, and you don't want to pass dispatch or the Redux store to it.
http://redux.js.org/docs/api/bindActionCreators.html#bindactioncreatorsactioncreators-dispatch


Higher order Components creator for Reflux

[mapActionsToProps(state, [ownProps]): actionProps] (Object or Function): If an object is passed, each function inside it will be assumed to be an action creator. An object with the same function names, will be merged into the component’s props. If a function is passed, it will be given dispatch. It’s up to you to return an object that somehow uses dispatch to bind action creators in your own way. If you omit it, will return empty object. https://www.npmjs.com/package/reflux-connect


mapStateToProps(state, [ownProps]): stateProps

If specified, the component will subscribe to GitBook store updates. Any time it updates, mapStateToProps will be called. Its result must be a plain object, and it will be merged into the component’s props.+
https://toolchain.gitbook.com/api/connect.html

Usage

connect(mapStateToProps, mapActionsToProps)

Tag cloud