react-state-custom 1.0.26 → 1.0.28
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/dev-tool/useHighlight.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +558 -436
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +4 -4
- package/dist/index.umd.js.map +1 -1
- package/dist/react-state-custom.css +1 -1
- package/dist/state-utils/createAutoCtx.d.ts +2 -1
- package/dist/state-utils/createRootCtx.d.ts +2 -1
- package/dist/state-utils/paramsToId.d.ts +24 -1
- package/dist/state-utils/useArrayChangeId.d.ts +18 -0
- package/package.json +25 -7
- 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.
|
|
@@ -267,6 +269,8 @@ function App() {
|
|
|
267
269
|
}
|
|
268
270
|
```
|
|
269
271
|
|
|
272
|
+
The toggle reveals a bottom-docked inspector that now uses resizable split panes powered by `@uiw/react-split`. Drag the gutter to adjust how much space the context list or detail view occupies while keeping your application visible above.
|
|
273
|
+
|
|
270
274
|
**Custom data viewer with rich object visualization:**
|
|
271
275
|
```typescript
|
|
272
276
|
import { DataViewComponent } from 'react-state-custom';
|
|
@@ -288,18 +292,20 @@ function useUserState({ userId }: { userId: string }) {
|
|
|
288
292
|
// State logic here
|
|
289
293
|
}
|
|
290
294
|
|
|
291
|
-
const { useCtxState:
|
|
295
|
+
const { useCtxState: useUserCtxState } = createAutoCtx(
|
|
292
296
|
createRootCtx('user', useUserState)
|
|
293
297
|
);
|
|
294
298
|
|
|
295
299
|
// Different instances for different users
|
|
296
300
|
function UserProfile({ userId }) {
|
|
297
|
-
const ctx =
|
|
301
|
+
const ctx = useUserCtxState({ userId }); // Automatic instance per userId
|
|
298
302
|
const { user } = useQuickSubscribe(ctx);
|
|
299
303
|
return <div>{user?.name}</div>;
|
|
300
304
|
}
|
|
301
305
|
```
|
|
302
306
|
|
|
307
|
+
> 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.
|
|
308
|
+
|
|
303
309
|
### Debounced Subscriptions
|
|
304
310
|
Optimize performance for frequently changing values:
|
|
305
311
|
|
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';
|