@abdulghani/reducercontext 中文文档教程
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
}