@acte/mook 中文文档教程
English | [简体中文](./README-cn.md) # mook easy to learn, no sample code, no useless render, global sharing of react state ## Install ```bash yarn add @acte/mook # Or npm install --save @acte/mook ``` ## Quick Start ### create a pair of hooks By calling `createHooks` with a custom Hook, it will return a pair of hooks, which is used for retrieving, updating and sharing data. ```jsx import { createHooks } from "mook"; import { useState } from "react"; function useCounter(initialValue) { const [count, setCount] = useState(initialValue ?? 0); const decrement = () => setCount(count - 1); const increment = () => { setCount(count + 1);} return { count, decrement, increment }; } export const {wrapped : useCounterModel, standin : useRefCounterModelRef} = createHooks(useCounter); ``` `wrapped` is the wrapped version hook of the input, it is used for retrieving data, updating data, and notifying its updates. `standin` is a special hook function,which has the same return value of `wrapped` function。 ### use the pair of hooks The wrapped hook can be use just once, while the standin hook can be used multiple times. ```jsx import {useCounterModel, useRefCounterModel } from "./couter-model"; function App(props) { return (
Component 1: {count}
); } function Component2(props) { const {count, increment, decrement} = useRefCounterModel(); return (Component 2: {count}
); } function Component3(props) { const {count, increment, decrement} = useRefCounterModel(); return (Component 3: {count}
); } ``` ## API ### createHooks ```typescript declare function createHooks
更多
你可能也喜欢
- @36node-lecha/chat-sdk-js 中文文档教程
- @4geit/swg-allow-cross-domain-helper 中文文档教程
- @540deg/react-scripts 中文文档教程
- @7polo/editorjs-image 中文文档教程
- @7polo/kityminder-core 中文文档教程
- @_koi/logs 中文文档教程
- @aardvarkxr/aardvark-react 中文文档教程
- @abcnews/alternating-case-to-object 中文文档教程
- @abhinavmir/corona 中文文档教程
- @absolute-web/vsf-newleaf 中文文档教程