1.0.1 • Published 5 years ago

truefit-redux-utils v1.0.1

Weekly downloads
14
License
MIT
Repository
github
Last release
5 years ago

truefit-redux-utils

This library is a set of redux util functions. These are patterns that we have used across projects and found to be helpful.

Install

npm install truefit-redux-utils

or

yarn add truefit-redux-utils

Reducers

State Reducer

An HOF that allows you to express your reducer as a series of states.

ParameterTypeDescription
initialStateanythe initial value of the reducer
statesjs objectthis object has the states (action types) as the keys, and the transforms as the values
import {stateReducer} from 'truefit-redux-utils';
import {ADD_ITEM, REMOVE_ITEM} from '../actions';

export default stateReducer([], {
  [ADD_ITEM]: (state, payload) => [...state, payload],
  [REMOVE_ITEM]: (state, payload) => state.splice(state.indexOf(payload), 1),
});