react-state-custom 1.0.25 → 1.0.27
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 +8 -4
- package/dist/dev-tool/useHighlight.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +615 -383
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +21 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/react-state-custom.css +1 -1
- package/dist/state-utils/createAutoCtx.d.ts +5 -4
- package/dist/state-utils/createRootCtx.d.ts +5 -1
- package/dist/state-utils/paramsToId.d.ts +22 -0
- package/dist/state-utils/useArrayChangeId.d.ts +18 -0
- package/package.json +25 -6
- package/dist/state-utils/useArrayHash.d.ts +0 -15
- package/dist/state-utils/useObjectHash.d.ts +0 -15
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ function useCounterState() {
|
|
|
37
37
|
// 2. Create shared context (one line!)
|
|
38
38
|
const { useCtxState } = createAutoCtx(createRootCtx('counter', useCounterState));
|
|
39
39
|
|
|
40
|
-
// 3. Add AutoRootCtx to your app root
|
|
40
|
+
// 3. Add AutoRootCtx to your app root (mount it once near the top of your tree)
|
|
41
41
|
function App() {
|
|
42
42
|
return (
|
|
43
43
|
<>
|
|
@@ -62,6 +62,8 @@ function Counter() {
|
|
|
62
62
|
}
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
> ℹ️ `AutoRootCtx` accepts optional `Wrapper` and `debugging` props. Pass an ErrorBoundary-like component through `Wrapper` to isolate failures, or set `debugging` to `true` to render raw state snapshots in the DOM (handy alongside React DevTools when tracking updates).
|
|
66
|
+
|
|
65
67
|
**That's it!** No reducers, no actions, no providers to wrap—just hooks.
|
|
66
68
|
|
|
67
69
|
## 🎯 Key Features
|
|
@@ -94,7 +96,7 @@ const { user, loading } = useDataSubscribeMultiple(ctx, 'user', 'loading');
|
|
|
94
96
|
```
|
|
95
97
|
|
|
96
98
|
### 3. **Automatic Context Management**
|
|
97
|
-
With `AutoRootCtx`, state contexts are automatically created and destroyed as needed. No manual provider management.
|
|
99
|
+
With `AutoRootCtx`, state contexts are automatically created and destroyed as needed. Mount it once near your application root, optionally providing a `Wrapper` (for error boundaries) or enabling `debugging` to render live state snapshots in the DOM—useful context when pairing with React DevTools. No manual provider management required.
|
|
98
100
|
|
|
99
101
|
### 4. **TypeScript First**
|
|
100
102
|
Full type inference and type safety throughout. Your IDE knows exactly what's in your state.
|
|
@@ -288,18 +290,20 @@ function useUserState({ userId }: { userId: string }) {
|
|
|
288
290
|
// State logic here
|
|
289
291
|
}
|
|
290
292
|
|
|
291
|
-
const { useCtxState:
|
|
293
|
+
const { useCtxState: useUserCtxState } = createAutoCtx(
|
|
292
294
|
createRootCtx('user', useUserState)
|
|
293
295
|
);
|
|
294
296
|
|
|
295
297
|
// Different instances for different users
|
|
296
298
|
function UserProfile({ userId }) {
|
|
297
|
-
const ctx =
|
|
299
|
+
const ctx = useUserCtxState({ userId }); // Automatic instance per userId
|
|
298
300
|
const { user } = useQuickSubscribe(ctx);
|
|
299
301
|
return <div>{user?.name}</div>;
|
|
300
302
|
}
|
|
301
303
|
```
|
|
302
304
|
|
|
305
|
+
> Need to avoid rapid mount/unmount churn? Pass a second argument to `createAutoCtx` (for example `createAutoCtx(rootCtx, 200)`) to keep instances alive for a few extra milliseconds before disposal.
|
|
306
|
+
|
|
303
307
|
### Debounced Subscriptions
|
|
304
308
|
Optimize performance for frequently changing values:
|
|
305
309
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Context, getContext, useDataContext, useDataSource, useDataSourceMultiple, useDataSubscribe, useDataSubscribeMultiple, useDataSubscribeMultipleWithDebounce, useDataSubscribeWithTransform } from './state-utils/ctx';
|
|
2
2
|
export { createRootCtx } from './state-utils/createRootCtx';
|
|
3
3
|
export { AutoRootCtx, createAutoCtx } from './state-utils/createAutoCtx';
|
|
4
|
-
export {
|
|
4
|
+
export { useArrayChangeId } from './state-utils/useArrayChangeId';
|
|
5
5
|
export { useQuickSubscribe } from './state-utils/useQuickSubscribe';
|
|
6
6
|
export { DevToolContainer } from './dev-tool/DevTool';
|
|
7
7
|
export type { DataViewComponent } from './dev-tool/DataViewComponent';
|