JSPM

react-combine-reducers

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7003
  • Score
    100M100P100Q131132F
  • License ISC

A helper utility to apply combineReducers functionality in react useReducer hook for large scale applications

Package Exports

  • react-combine-reducers

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-combine-reducers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React Combine Reducers

A helper utility to apply combineReducers functionality in react useReducer hook.

Installation

Install the module by running -

$ npm install react-combine-reducers

Usage

Import the helper function -

import combineReducers from 'react-combine-reducers';

The function takes an object of the following structure -

const [rootReducerCombined, initialStateCombined] = combineReducers({ reducerOne: [reducerOne, initialStateOne], reducertwo: [reducerTwo, initialStateTwo] });

Example -

    const initialStateOne = {
        name: "Harry",
        city: "London"
    }
    const initialStateTwo = {
        country: "UK",
        userID: 1001
    }
    const reducerOne = (state, action) => {
        switch (action.type) {
            case "ACTION_ONE": return { ...state, name: "Puli" };
            default: return state;
        }
    }
    const reducerTwo = (state, action) => {
        switch (action.type) {
            case "ACTION_TWO": return { ...state, country: "Germany" };
            default: return state;
        }
    }
    const [rootReducerCombined, initialStateCombined] = combineReducers({
        reducerOne: [reducerOne, initialStateOne],
        reducertwo: [reducerTwo, initialStateTwo]
    });
    const [state, dispatch] = useReducer(rootReducerCombined, initialStateCombined);

Issues:

If you find a bug, please file an issue on our issue tracker on github.

Give us a star if this helped you! Cheers!