Skip to content

Commit 7342bf4

Browse files
committed
docs(v4.1.0): update api docs
1 parent b0994bd commit 7342bf4

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

96140
Every model has its own state and actions.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-model",
3-
"version": "4.1.0-alpha.3",
3+
"version": "4.1.0",
44
"description": "The State management library for React",
55
"main": "./dist/react-model.js",
66
"module": "./dist/react-model.esm.js",

src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ function useModel<S>(
6969
// pass update event to other components subscribe the same store
7070
return await applyMiddlewares(actionMiddlewares, context)
7171
}
72-
console.log('Global.mutableState[storeId]: ', Global.mutableState[storeId])
7372
return [Global.mutableState[storeId][index], setter]
7473
}
7574

0 commit comments

Comments
 (0)