Skip to content

Instantly share code, notes, and snippets.

@n0f3 n0f3/snippets.js
Last active Feb 20, 2018

What would you like to do?
Learn redux snippets #javascript
// This enables hot loading for reducers
if ( {'./reducers/', () => {
// using require because the import syntax is required to be declared
// at the top of the file
const nextRootReducer = rquire('./reducers/index').default;
// Enabling redux dev tools if present
const enhancers = compose(
window.devToolsExtension ? window.devToolsExtension() : (f) => f
const store = createStore(rootReducer, defaultState, enhancers);
// If we want to avoid having to write store.dispatch we can use this
// convenience method
// bindActionCreators(): Turns an object whose values are action creators, into an object with the same keys, but with every function wrapped into a dispatch call so they may be invoked directly. This is just a convenience method, as you can call store.dispatch(MyActionCreators.doSomething()) yourself just fine.
For convenience, you can also pass a single function as the first argument, and get a function in return.
function mapDispatchToProps(dispatch) {
return bindActionCreators(actionCreators, dispatch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.