Skip to content

Create reducer without messy looking switch statements.

Notifications You must be signed in to change notification settings

vkbr/clean-redux-reducer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Redux Reducer

Create reducer without messy looking switch statements.

Installation

NPM:

npm install clean-redux-reducer

Yarn:

yarn add clean-redux-reducer

Usage

// reducer.js
import CreateReducer from 'clean-redux-reducer';

const initialState = {
	// ...
	tick: 0,
};

function onIncrement(state, action) {
	return {
		...state,
		tick: state.tick + (action.incrementBy || 1),
	};
}

function onDecrement(state, action) {
	return {
		...state,
		tick: state.tick - (action.incrementBy || 1),
	};
}

const reducer = CreateReducer
	.fromInitialState(initialState)
	.addCase('INCREMENT', onIncrement)
	.addCase('DECREMENT', onDecrement)
	.finalizeReducer();

export default reducer;

About

Create reducer without messy looking switch statements.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published