3.0.1 • Published 7 months ago
oz-redux-reducer v3.0.1
oz-redux-reducer
This utility reduces the boilerplate for Redux store reducers.
In one function you will have both the reducer and the actions without the need for types.
No more switch cases
No more types
Works with:
Example:
Install:
npm i oz-redux-reducer
Usage:
./src/store/reducers/demo-reducer.ts
import { Dispatch } from "redux";
import { buildReducer } from "oz-redux-reducer";
export const [demoReducer, demoActions] = buildReducer({
// initial state
text: "<some init value>s",
// actions
setText(state: object, newValue: string) {
return { ...state, text: newValue };
},
async fetchText(dispatch: Dispatch) {
const value = await fetch(/*...*/);
dispatch(demoActions.setText(value));
};
});
.src/store/actions.ts
export { demoActions } from "./reducers/demo-reducer.ts
./src/store/reducers/index.ts
import { combineReducers } from "redux";
import { demoReducer } from "./demo-reducer";
export default combineReducers({
demo: demoReducer,
});
calling actions:
import { demoActions } from "./demo-reducer";
// in compnent or hook
dispatch(demoActions.setText("newText"));
Now replace old reducers with new ozReducer 😉
3.0.1
7 months ago
3.0.0
7 months ago
2.1.2
8 months ago
2.1.1
8 months ago
2.1.3
8 months ago
2.0.11
8 months ago
2.0.9
2 years ago
2.0.8
2 years ago
2.0.3
2 years ago
2.0.2
2 years ago
2.0.5
2 years ago
2.0.4
2 years ago
2.0.7
2 years ago
2.0.6
2 years ago
2.0.1
2 years ago
2.0.0
2 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago