mobx-react-use-autorun 3.0.43 → 3.0.45
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 +10 -4
- package/dist/lib/useMobxState.d.ts +2 -1
- package/dist/lib/useMobxState.js.map +1 -1
- package/lib/lib/useMobxState.tsx +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,13 @@ Builds the files for production to the `dist` folder.<br/>
|
|
|
22
22
|
|
|
23
23
|
Publish to npm repository
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## `Installation`
|
|
26
|
+
|
|
27
|
+
npm install mobx-react-use-autorun
|
|
28
|
+
|
|
29
|
+
## `Usage`
|
|
30
|
+
|
|
31
|
+
### Notes - Define state and props with useMobxState
|
|
26
32
|
|
|
27
33
|
import { useMobxState, observer } from 'mobx-react-use-autorun';
|
|
28
34
|
import { useRef } from 'react';
|
|
@@ -124,7 +130,7 @@ The second:
|
|
|
124
130
|
|
|
125
131
|
Provide a method to generate state, the state is executed only once, and the performance is better.<br/>
|
|
126
132
|
|
|
127
|
-
|
|
133
|
+
### Notes - Subscription property changes with useMobxEffect
|
|
128
134
|
|
|
129
135
|
import { useMobxState, observer } from 'mobx-react-use-autorun';
|
|
130
136
|
import { useMobxEffect, toJS } from 'mobx-react-use-autorun'
|
|
@@ -142,7 +148,7 @@ Provide a method to generate state, the state is executed only once, and the per
|
|
|
142
148
|
</div>
|
|
143
149
|
})
|
|
144
150
|
|
|
145
|
-
|
|
151
|
+
### Notes - Get the real data of the proxy object with toJS
|
|
146
152
|
|
|
147
153
|
toJS will cause data to be used, please do not execute toJS(state) in component rendering code, it may cause repeated rendering. Wrong Usage Demonstration:<br/>
|
|
148
154
|
|
|
@@ -181,7 +187,7 @@ Other than that, all usages are correct. Example:<br/>
|
|
|
181
187
|
return <button onClick={() => console.log(toJS(state))}>{'Click Me'}</button>;
|
|
182
188
|
})
|
|
183
189
|
|
|
184
|
-
|
|
190
|
+
### Notes - Define global mutable data
|
|
185
191
|
|
|
186
192
|
import { observable } from 'mobx-react-use-autorun';
|
|
187
193
|
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function useMobxState<T extends Record<any, any
|
|
1
|
+
export declare function useMobxState<T extends Record<any, any>>(state: T | (() => T)): T;
|
|
2
|
+
export declare function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props: P): T & P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMobxState.js","sourceRoot":"","sources":["../../lib/lib/useMobxState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"useMobxState.js","sourceRoot":"","sources":["../../lib/lib/useMobxState.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKrD,MAAM,UAAU,YAAY,CAAyD,KAAoB,EAAE,KAAS;IAChH,IAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAa,CAAC,CAAC,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;IAEjG,WAAW,CAAC;;;QAER,IAAI,KAAK,EAAE;YACP,KAAK,IAAM,GAAG,IAAI,KAAK,EAAE;gBACrB,IAAI,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAI,MAAA,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,0CAAE,GAAG,CAAA,EAAE;oBAC9E,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAQ,CAAC,CAAA;iBAC5F;qBAAM;oBACH,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,GAAG,CAAC,EAAE;wBAC/B,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;wBACvB,gBAAgB,CAAC,SAAS,YAAI,GAAC,GAAG,IAAG,KAAK,CAAC,GAAG,CAAC,iBAAM,GAAC,GAAG,IAAG,KAAK,MAAG,CAAA;qBACvE;iBACJ;aACJ;SACJ;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,SAAgB,CAAC;AAC5B,CAAC"}
|
package/lib/lib/useMobxState.tsx
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { extendObservable, remove, isObservable, runInAction } from 'mobx';
|
|
2
2
|
import { useLocalObservable } from 'mobx-react-lite';
|
|
3
3
|
|
|
4
|
+
export function useMobxState<T extends Record<any, any>>(state: T | (() => T)): T;
|
|
5
|
+
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props: P): T & P;
|
|
6
|
+
|
|
4
7
|
export function useMobxState<T extends Record<any, any>, P extends Record<any, any>>(state: T | (() => T), props?: P): T & P {
|
|
5
8
|
const mobxState = useLocalObservable(typeof state === "function" ? (state as any) : () => state);
|
|
6
9
|
|
|
@@ -21,4 +24,4 @@ export function useMobxState<T extends Record<any, any>, P extends Record<any, a
|
|
|
21
24
|
})
|
|
22
25
|
|
|
23
26
|
return mobxState as any;
|
|
24
|
-
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mobx-react-use-autorun","version":"3.0.
|
|
1
|
+
{"name":"mobx-react-use-autorun","version":"3.0.45","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.7.0","mobx-react-lite":"3.4.0","react-use":"17.4.0","rxjs":"7.5.7"},"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/"}}
|