@ackee/redux-utils

Common Redux utilities - reducer factories, utility for generating action types.

Usage no npm install needed!

<script type="module">
  import ackeeReduxUtils from 'https://cdn.skypack.dev/@ackee/redux-utils';
</script>

README

ackee|redux-utils

GitHub license"> CI Status PRs Welcome Dependency Status bundlephobia bundlephobia

Redux Utilities

Common Redux utilities, including:

  • Reducer factories (containerReducer, resetReducer, basicApiReducer a more).
  • Generic API request action type and creator factories (asyncType, apiRequestActions).

Table of contents


Installing

Using yarn:

$ yarn add @ackee/redux-utils

Using npm:

$ npm i -S @ackee/redux-utils

Configuration (optional)

Available options:

  • Set initial reducer state globally.
  • Set custom logger.
import { configure } from '@ackee/redux-utils';

// Defaults:
configure({
    // Pass any object with error, warn and info methods.
    logger: console,

    containerReducer: reducerConfig => reducerConfig,
    basicApiReducer: reducerConfig => reducerConfig,
    paginationApiReducer: reducerConfig => reducerConfig,
    infiniteListApiReducer: reducerConfig => reducerConfig,
});

Change reducer initial state globally

import { configure } from '@ackee/redux-utils';

configure({
    // ...

    basicApiReducer: ({ initialState, ...rest }) => {
        return {
            ...rest,
            initialState: {
                ...initialState,
                // Override default error initial value:
                error: null,
            },
        };
    },
});