redux-sugar-store
v1.0.0
Published
Small Redux store creator with the main goal to make creating small and mediul react/redux apps easier. It's hiding the action and making dispatching look like calling a simple function/reducer. The default behavior of the redux store, actions and reducer
Downloads
15
Maintainers
Readme
redux-sugar-store
Redux store sprinkled with some sugar. The "redux-sugar-store" will get all reducers and create a standart actions ({type ..., payload ...}) with the same name. It will create methods in the store so actions can be dispatched directly like plain functions.
(depending on redux)
Sample usage:
import sugarStore from 'redux-sugar-store';
import { createStore } from 'redux';
const initialState = {};
const reducers = [
{
exampleReducer: (state, action) => state
}, {
exampleReducer: (state, action) => state
}, {
anotherReducer: (state, action) => state
}
];
const store = sugarStore(createStore, initialState, reducers);
export default store;
Dispatching events
store.exampleReducer(payload);
Using connect
mapStoreToProps - will get a store reference in the ListConnected component. So store.exampleReducer(payload); can be called in the component as it can be called outside.
const ListConnected = connect((store) => ({
user: store.users
}), store.mapStoreToProps)(List);