🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

create-reducer-object

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-reducer-object

This is a very simple helper library. Traditionally, according to the Redux documentation, reducers are written like this:

2.0.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

create-reducer-object

This is a very simple helper library. Traditionally, according to the Redux documentation, reducers are written like this:

function myFirstReducer(state, action) {
  switch (action.type) {
    case 'TODO_ADDED':
      return todoAdded(state, action);
  }

  return state;
}

This results in long, unwieldy switch statements when you have many different actions.

You can write the equivalent of the above, using this library, as follows:

import { createReducerObject } from 'create-reducer-object';

const initialState = {
  todos: [],
};

const myFirstReducer = createReducerObject({
  TODO_ADDED: todoAdded
}, initialState);

Typescript compatibility

The module is written in and fully compatible with Typescript. You can define your state like so:

import { createReducerObject } from 'create-reducer-object';

type State = {
  todos: Todo[];
};

const initialState: State = {
  todos: [],
};

const myFirstReducer = createReducerObject<State>({
  TODO_ADDED: todoAdded,
}, initialState);

FAQs

Package last updated on 03 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts