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 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: useUserState } = createAutoCtx(
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 = useUserState({ userId }); // Automatic instance per userId
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
 
@@ -1,6 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  export declare function useHighlight(filterString: string): {
3
- highlight: RegExp;
3
+ highlight: RegExp | undefined;
4
4
  };
5
5
  export declare const HightlightWrapper: React.FC<{
6
6
  highlight: string;
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 { useArrayHash } from './state-utils/useArrayHash';
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';