@mhub/web-redux-utilities
v0.0.4
Published
MHub Web Redux Utilities
Downloads
6
Readme
MHub Web Redux Utilities
Getting Started
Install package.
yarn add redux @mhub/web-redux-utilities
Setup reducer.
import { createReducer } from '@mhub/web-redux-utilities'; const INCREMENT = 'INCREMENT'; const DECREMENT = 'DECREMENT'; const initialState = { count: 0, }; export default createReducer(initialState, { [INCREMENT]: state => ( Object.assign({}, state, { count: state.count + 1, }) ), [DECREMENT]: state => ( Object.assign({}, state, { count: state.count - 1, }) ), });
Combine reducers.
import { combineReducers } from 'redux'; import counter from './counter/reducers'; export default combineReducers({ counter, });
Setup React App.
import React from 'react'; import ReactDOM from 'react-dom'; import { configureStore } from '@mhub/web-redux-utilities'; import thunk from 'redux-thunk'; import { connectRouter, routerMiddleware } from 'connected-react-router'; import { createBrowserHistory } from 'history'; import Root from './Root'; import rootReducer from './redux/reducers'; const history = createBrowserHistory(); const store = configureStore( connectRouter(history)(rootReducer), {}, thunk, routerMiddleware(history), ); ReactDOM.render( <Root store={store} history={history} />, document.getElementById('root'), );