@ackee/redux-utils 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

ackee|redux-utils

GitHub licenseCI StatusPRs WelcomeDependency Statusbundlephobiabundlephobia

Redux Utilities

常用的 Redux 实用程序,包括:

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

Table of contents


Installing

使用 yarn:

$ yarn add @ackee/redux-utils

使用 npm:

$ npm i -S @ackee/redux-utils

Configuration (optional)

可用选项:

  • 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,
            },
        };
    },
});

ackee|redux-utils

GitHub licenseCI StatusPRs WelcomeDependency Statusbundlephobiabundlephobia

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,
            },
        };
    },
});
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文