@@ -8,15 +8,7 @@ The State management library for React
8
8
9
9
## Quick Start
10
10
11
- Running demo
12
-
13
- ```
14
- git clone https://github.com/byte-fe/react-modelx.git
15
- cd react-model/example
16
- npm i
17
- npm run initial
18
- npm run dev
19
- ```
11
+ [ Next.js + react-modelx work around] ( https://github.com/ArrayZoneYour/react-modelx-experiment )
20
12
21
13
install package
22
14
@@ -30,8 +22,6 @@ npm install react-modelx
30
22
31
23
react-model keep the state and actions in a global store. So you need to register them before using.
32
24
33
- ` index.ts `
34
-
35
25
``` typescript
36
26
import { Model } from ' react-modelx'
37
27
import Home from ' ../model/home.model'
@@ -42,18 +32,6 @@ const models = { Home, Shared }
42
32
export const { useStore } = Model (models )
43
33
```
44
34
45
- ` index.js `
46
-
47
- ``` javascript
48
- import { Model } from ' react-modelx'
49
- import Home from ' ../model/home.model'
50
- import Shared from ' ../model/shared.model'
51
-
52
- const models = { Home, Shared }
53
-
54
- export const { useStore } = Model (models)
55
- ```
56
-
57
35
### useStore
58
36
59
37
The functional component in React 16.7 can use Hooks to connect the global store.
@@ -102,7 +80,7 @@ type ActionsParamType = {
102
80
get: undefined
103
81
} // You only need to tag the type of params here !
104
82
105
- const Model = {
83
+ const Model: ModelType < StateType , ActionsParamType > = {
106
84
actions: {
107
85
increment : async (state , _ , params ) => {
108
86
return {
@@ -133,7 +111,7 @@ const Model = {
133
111
}
134
112
},
135
113
state: initialState
136
- } as ModelType < StateType , ActionsParamType > // The Modal actions type will generate automatically by the StateType and ActionParamsType
114
+ }
137
115
138
116
export default Model
139
117
@@ -205,7 +183,7 @@ JavaScript Example
205
183
const Model = {
206
184
actions: {
207
185
increment: async (s , _ , params ) => {
208
- return ( state : typeof s ) => {
186
+ return state => {
209
187
state .counter += params || 1
210
188
}
211
189
}
0 commit comments