@abdulghani/reducercontext 中文文档教程

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

React Reducer Context

使用 reducer 提供 & 在上下文中维护状态

Installation

npm npm install @abdulghani/reducercontext\ yarn yarn add @abdulghani/reducercontext

Usage

提供 reducer

import ReducerContext from "@abdulghani/reducercontext";
import reducer from "somewhere"
import ChildrenComponent from "somewhere"

const ParentComponent = () => {
  return (
    <ReducerContext reducer={reducer}>
      <ChildrenComponent/>
    </ReducerContext>
  )
}

访问状态 & 派遣

import {useSelector, useDispatch, useThunk} from "@abdulghani/reducercontext";

const ChildrenComponent = () => {
  const state = useSelector(state => state);
  const dispatch = useDispatch();
  const thunk = useThunk();

  // use them
}

React Reducer Context

use reducer to provide & maintain state inside context

Installation

npm npm install @abdulghani/reducercontext\ yarn yarn add @abdulghani/reducercontext

Usage

Provide the reducer

import ReducerContext from "@abdulghani/reducercontext";
import reducer from "somewhere"
import ChildrenComponent from "somewhere"

const ParentComponent = () => {
  return (
    <ReducerContext reducer={reducer}>
      <ChildrenComponent/>
    </ReducerContext>
  )
}

Access the state & dispatch

import {useSelector, useDispatch, useThunk} from "@abdulghani/reducercontext";

const ChildrenComponent = () => {
  const state = useSelector(state => state);
  const dispatch = useDispatch();
  const thunk = useThunk();

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