mobx-react-use-autorun 3.0.33 → 3.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,12 +103,15 @@ useMobxState provides two usages.<br/>
|
|
|
103
103
|
|
|
104
104
|
is easy to use, you can define state and third-party hooks.<br/>
|
|
105
105
|
|
|
106
|
-
useMobxState(()=>({
|
|
106
|
+
useMobxState(() => ({
|
|
107
107
|
get (){
|
|
108
108
|
return state.name
|
|
109
109
|
},
|
|
110
110
|
name: string = 'tom',
|
|
111
|
-
}),{
|
|
111
|
+
}),{
|
|
112
|
+
...props,
|
|
113
|
+
intl: useIntl(),
|
|
114
|
+
})
|
|
112
115
|
|
|
113
116
|
provides advanced usage, the state is executed only once, and the performance is better. At the same time, you can use the get computed property to recalculate when the computed value changes.<br/>
|
|
114
117
|
|
|
@@ -173,7 +176,14 @@ Other than that, all usages are correct. Example:<br/>
|
|
|
173
176
|
|
|
174
177
|
import { observable } from 'mobx-react-use-autorun';
|
|
175
178
|
|
|
176
|
-
const
|
|
179
|
+
export const globalState = observable({
|
|
180
|
+
age: 15
|
|
181
|
+
name: 'tom'
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
export async function setName(name: string){
|
|
185
|
+
globalState.name = name
|
|
186
|
+
}
|
|
177
187
|
|
|
178
188
|
## Introduction to third-party hooks
|
|
179
189
|
|
|
@@ -182,22 +192,27 @@ useUnmount is executed when the component is unmount.<br/>
|
|
|
182
192
|
|
|
183
193
|
import { useMount, useUnmount } from 'react-use'
|
|
184
194
|
import { Subscription, of, tap } from 'rxjs'
|
|
185
|
-
import { useMobxState } from 'mobx-react-use-autorun'
|
|
195
|
+
import { useMobxState, observer } from 'mobx-react-use-autorun'
|
|
186
196
|
|
|
187
|
-
|
|
188
|
-
subscription: new Subscription()
|
|
189
|
-
})
|
|
197
|
+
export default observer(() => {
|
|
190
198
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
const state = useMobxState({
|
|
200
|
+
subscription: new Subscription()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
useMount(() => {
|
|
204
|
+
state.subscription.add(of(null).pipe(
|
|
205
|
+
tap(() => {
|
|
206
|
+
console.log('component is loaded')
|
|
207
|
+
})
|
|
208
|
+
).subscribe())
|
|
209
|
+
})
|
|
198
210
|
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
useUnmount(() => {
|
|
212
|
+
state.subscription.unsubscribe()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
return null;
|
|
201
216
|
})
|
|
202
217
|
|
|
203
218
|
## Learn More
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mobx-react-use-autorun","version":"3.0.
|
|
1
|
+
{"name":"mobx-react-use-autorun","version":"3.0.35","description":"React Hook for mobx","scripts":{"test":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_test.ts","build":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_build.ts","make":"npx -y -p typescript -p ts-node ts-node --skipProject bin/mobx_react_make.ts"},"dependencies":{"mobx":">=6.5.0","mobx-react-lite":">=3.3.0","react-use":">=17.3.2","rxjs":">=6.0.0"},"peerDependencies":{"react":">=16.8.0"},"license":"MIT","keywords":["react","mobx","typescript"],"main":"./dist/index.js","types":"./dist/index.d.ts","eslintConfig":{"extends":["react-app","react-app/jest"]},"homepage":"https://github.com/zdu-strong/mobx-react-use-autorun#readme","repository":{"type":"git","url":"git+https://github.com/zdu-strong/mobx-react-use-autorun.git"},"files":["lib","dist"],"bugs":{"url":"https://github.com/zdu-strong/mobx-react-use-autorun/issues"},"publishConfig":{"registry":"https://registry.npmjs.org/"}}
|