@@ -50,6 +50,8 @@ const TodoList = () => {
5050
5151## Quick Start
5252
53+ [ createStore + useModel] ( https://codesandbox.io/s/createstore-usemodal-all-of-your-state-4u8s6 )
54+
5355[ CodeSandbox: TodoMVC] ( https://codesandbox.io/s/moyxon99jx )
5456
5557[ Next.js + react-model work around] ( https://github.com/byte-fe/react-model-experiment )
@@ -65,6 +67,7 @@ npm install react-model
6567## Table of Contents
6668
6769- [ Core Concept] ( #core-concept )
70+ - [ createStore] ( #createstore )
6871 - [ Model] ( #model )
6972 - [ Model Register] ( #model-register )
7073 - [ useStore] ( #usestore )
@@ -91,6 +94,47 @@ npm install react-model
9194
9295## Core Concept
9396
97+ ### createStore
98+
99+ You can create a shared / local store by createStore api.
100+
101+ [ Online Demo] ( https://codesandbox.io/s/createstore-usemodal-all-of-your-state-4u8s6 )
102+
103+ ` model/counter.ts `
104+
105+ ``` typescript
106+ import { useState } from ' react'
107+ import { useModel } from ' react-model'
108+ const { useStore } = createStore (() => {
109+ const [localCount, setLocalCount] = useState (1 ) // Local State, Independent in different components
110+ const [count, setCount] = useModel (1 ) // Global State, the value is the same in different components
111+ const incLocal = () => {
112+ setLocalCount (localCount + 1 )
113+ }
114+ const inc = () => {
115+ setCount (c => c + 1 )
116+ }
117+ return { count , localCount , incLocal , inc }
118+ })
119+
120+ export default useStore
121+ ```
122+
123+ ` page/counter-1.tsx `
124+
125+ ``` tsx
126+ import useSharedCounter from ' models/global-counter'
127+ const Page = () => {
128+ const { count, localCount, inc, incLocal } = useStore ()
129+ return <div >
130+ <span >count: { count } </span >
131+ <span >localCount: { localCount } </span >
132+ <button onClick = { inc } >inc</button >
133+ <button onClick = { incLocal } >incLocal</button >
134+ </div >
135+ }
136+ ```
137+
94138### Model
95139
96140Every model has its own state and actions.
0 commit comments