Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reduce-reducers

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reduce-reducers

Reduce multiple reducers into a single reducer

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
370K
decreased by-19.41%
Maintainers
2
Weekly downloads
 
Created

What is reduce-reducers?

The reduce-reducers npm package allows you to combine multiple reducer functions into a single reducer function. This is particularly useful in state management scenarios, such as with Redux, where you may want to split the logic for handling different parts of the state into separate reducers and then combine them.

What are reduce-reducers's main functionalities?

Combining Multiple Reducers

This feature allows you to combine multiple reducers into a single reducer function. The code sample demonstrates how to combine a countReducer and a textReducer into a rootReducer using reduce-reducers.

const { combineReducers } = require('redux');
const reduceReducers = require('reduce-reducers');

const initialState = { count: 0, text: '' };

const countReducer = (state = initialState.count, action) => {
  switch (action.type) {
    case 'INCREMENT':
      return state + 1;
    case 'DECREMENT':
      return state - 1;
    default:
      return state;
  }
};

const textReducer = (state = initialState.text, action) => {
  switch (action.type) {
    case 'SET_TEXT':
      return action.text;
    default:
      return state;
  }
};

const rootReducer = reduceReducers(
  (state = initialState, action) => state,
  combineReducers({ count: countReducer, text: textReducer })
);

console.log(rootReducer(undefined, { type: 'INCREMENT' })); // { count: 1, text: '' }
console.log(rootReducer(undefined, { type: 'SET_TEXT', text: 'Hello' })); // { count: 0, text: 'Hello' }

Other packages similar to reduce-reducers

Keywords

FAQs

Package last updated on 05 May 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc