@aweebit/react-essentials 0.10.5 → 0.10.7

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.
Files changed (40) hide show
  1. package/README.md +124 -31
  2. package/dist/hooks/index.d.ts +1 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +1 -0
  5. package/dist/hooks/index.js.map +1 -1
  6. package/dist/hooks/useEventListener.d.ts.map +1 -1
  7. package/dist/hooks/useEventListener.js +2 -1
  8. package/dist/hooks/useEventListener.js.map +1 -1
  9. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +7 -0
  10. package/dist/hooks/useIsomorphicLayoutEffect.d.ts.map +1 -0
  11. package/dist/hooks/useIsomorphicLayoutEffect.js +7 -0
  12. package/dist/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  13. package/dist/hooks/useReducerWithDeps.d.ts +2 -2
  14. package/dist/hooks/useReducerWithDeps.d.ts.map +1 -1
  15. package/dist/hooks/useReducerWithDeps.js +3 -3
  16. package/dist/hooks/useReducerWithDeps.js.map +1 -1
  17. package/dist/hooks/useStateWithDeps.d.ts +2 -2
  18. package/dist/hooks/useStateWithDeps.js +2 -2
  19. package/dist/misc/contextualize.d.ts +5 -5
  20. package/dist/misc/contextualize.d.ts.map +1 -1
  21. package/dist/misc/contextualize.js.map +1 -1
  22. package/dist/misc/createSafeContext.d.ts +1 -2
  23. package/dist/misc/createSafeContext.d.ts.map +1 -1
  24. package/dist/misc/createSafeContext.js.map +1 -1
  25. package/dist/misc/wrapJSX.d.ts +3 -3
  26. package/dist/misc/wrapJSX.d.ts.map +1 -1
  27. package/dist/misc/wrapJSX.js.map +1 -1
  28. package/dist/utils.d.ts +0 -1
  29. package/dist/utils.d.ts.map +1 -1
  30. package/dist/utils.js.map +1 -1
  31. package/package.json +12 -12
  32. package/src/hooks/index.ts +1 -0
  33. package/src/hooks/useEventListener.ts +2 -1
  34. package/src/hooks/useIsomorphicLayoutEffect.ts +15 -0
  35. package/src/hooks/useReducerWithDeps.ts +8 -3
  36. package/src/hooks/useStateWithDeps.ts +2 -2
  37. package/src/misc/contextualize.tsx +7 -6
  38. package/src/misc/createSafeContext.ts +3 -2
  39. package/src/misc/wrapJSX.tsx +4 -7
  40. package/src/utils.ts +0 -6
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![NPM Version](https://img.shields.io/npm/v/%40aweebit%2Freact-essentials)](https://www.npmjs.com/package/@aweebit/react-essentials)
4
4
 
5
5
  - [useEventListener()](#useeventlistener)
6
+ - [useIsomorphicLayoutEffect()](#useisomorphiclayouteffect)
6
7
  - [useReducerWithDeps()](#usereducerwithdeps)
7
8
  - [useStateWithDeps()](#usestatewithdeps)
8
9
  - [contextualize()](#contextualize)
@@ -20,7 +21,7 @@
20
21
  const useEventListener: UseEventListener;
21
22
  ```
22
23
 
23
- Defined in: [hooks/useEventListener.ts:135](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L135)
24
+ Defined in: [hooks/useEventListener.ts:136](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L136)
24
25
 
25
26
  Adds `handler` as a listener for the event `eventName` of `target` with the
26
27
  provided `options` applied
@@ -61,6 +62,60 @@ useEventListener(buttonRef, 'click', () => console.log('click'));
61
62
 
62
63
  ---
63
64
 
65
+ ## useIsomorphicLayoutEffect()
66
+
67
+ ```ts
68
+ const useIsomorphicLayoutEffect: (effect, deps?) => void;
69
+ ```
70
+
71
+ Defined in: [hooks/useIsomorphicLayoutEffect.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useIsomorphicLayoutEffect.ts#L12)
72
+
73
+ Identical to [`useLayoutEffect`](https://react.dev/reference/react/useLayoutEffect), except it does not result in
74
+ warnings when used on the server
75
+
76
+ ### Parameters
77
+
78
+ <table>
79
+ <thead>
80
+ <tr>
81
+ <th>Parameter</th>
82
+ <th>Type</th>
83
+ </tr>
84
+ </thead>
85
+ <tbody>
86
+ <tr>
87
+ <td>
88
+
89
+ `effect`
90
+
91
+ </td>
92
+ <td>
93
+
94
+ `EffectCallback`
95
+
96
+ </td>
97
+ </tr>
98
+ <tr>
99
+ <td>
100
+
101
+ `deps?`
102
+
103
+ </td>
104
+ <td>
105
+
106
+ `DependencyList`
107
+
108
+ </td>
109
+ </tr>
110
+ </tbody>
111
+ </table>
112
+
113
+ ### Returns
114
+
115
+ `void`
116
+
117
+ ---
118
+
64
119
  ## useReducerWithDeps()
65
120
 
66
121
  ```ts
@@ -71,10 +126,10 @@ function useReducerWithDeps<S, A>(
71
126
  ): [S, ActionDispatch<A>];
72
127
  ```
73
128
 
74
- Defined in: [hooks/useReducerWithDeps.ts:59](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useReducerWithDeps.ts#L59)
129
+ Defined in: [hooks/useReducerWithDeps.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useReducerWithDeps.ts#L64)
75
130
 
76
- `useReducer` hook with an additional dependency array `deps` that resets the
77
- state to `initialState` when dependencies change
131
+ [`useReducer`](https://react.dev/reference/react/useReducer) hook with an additional dependency array `deps` that
132
+ resets the state to `initialState` when dependencies change
78
133
 
79
134
  This hook is the reducer pattern counterpart of [`useStateWithDeps`](#usestatewithdeps).
80
135
 
@@ -214,10 +269,10 @@ function useStateWithDeps<S>(
214
269
  ): [S, Dispatch<SetStateAction<S>>];
215
270
  ```
216
271
 
217
- Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useStateWithDeps.ts#L62)
272
+ Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useStateWithDeps.ts#L62)
218
273
 
219
- `useState` hook with an additional dependency array `deps` that resets the
220
- state to `initialState` when dependencies change
274
+ [`useState`](https://react.dev/reference/react/useState) hook with an additional dependency array `deps` that
275
+ resets the state to `initialState` when dependencies change
221
276
 
222
277
  Due to React's limitations, a change in dependencies always causes two
223
278
  renders when using this hook. The result of the first render is thrown away
@@ -341,10 +396,10 @@ Dependencies that reset the state to `initialState`
341
396
  ## contextualize()
342
397
 
343
398
  ```ts
344
- function contextualize(children): ContextualizePipe;
399
+ function contextualize<Children>(children): ContextualizePipe<Children>;
345
400
  ```
346
401
 
347
- Defined in: [misc/contextualize.tsx:79](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L79)
402
+ Defined in: [misc/contextualize.tsx:78](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L78)
348
403
 
349
404
  An alternative way to provide context values to component trees that avoids
350
405
  ever-increasing indentation
@@ -386,6 +441,25 @@ return contextualize(jsx)
386
441
  .end();
387
442
  ```
388
443
 
444
+ ### Type Parameters
445
+
446
+ <table>
447
+ <thead>
448
+ <tr>
449
+ <th>Type Parameter</th>
450
+ </tr>
451
+ </thead>
452
+ <tbody>
453
+ <tr>
454
+ <td>
455
+
456
+ `Children` _extends_ `ReactNode`
457
+
458
+ </td>
459
+ </tr>
460
+ </tbody>
461
+ </table>
462
+
389
463
  ### Parameters
390
464
 
391
465
  <table>
@@ -405,7 +479,7 @@ return contextualize(jsx)
405
479
  </td>
406
480
  <td>
407
481
 
408
- `ReactNode`
482
+ `Children`
409
483
 
410
484
  </td>
411
485
  <td>
@@ -419,7 +493,7 @@ The children to contextualize
419
493
 
420
494
  ### Returns
421
495
 
422
- [`ContextualizePipe`](#contextualizepipe)
496
+ [`ContextualizePipe`](#contextualizepipe)\<`Children`\>
423
497
 
424
498
  An object with the following properties:
425
499
 
@@ -444,7 +518,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
444
518
  };
445
519
  ```
446
520
 
447
- Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/createSafeContext.ts#L62)
521
+ Defined in: [misc/createSafeContext.ts:61](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/createSafeContext.ts#L61)
448
522
 
449
523
  For a given type `T`, returns a function that produces both a context of that
450
524
  type and a hook that returns the current context value if one was provided,
@@ -570,7 +644,7 @@ A function that accepts a single string argument `displayName` (e.g.
570
644
  </td>
571
645
  <td>
572
646
 
573
- \[`T`\] _extends_ \[`never`\] ? `never` : `ArgumentFallback`\<`DisplayName`, `never`, `string`\>
647
+ \[`T`\] _extends_ \[`never`\] ? `never` : `string` _extends_ `DisplayName` ? `never` : `DisplayName`
574
648
 
575
649
  </td>
576
650
  </tr>
@@ -589,7 +663,7 @@ A function that accepts a single string argument `displayName` (e.g.
589
663
  function wrapJSX<Children>(children): JSXWrapPipe<Children>;
590
664
  ```
591
665
 
592
- Defined in: [misc/wrapJSX.tsx:99](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L99)
666
+ Defined in: [misc/wrapJSX.tsx:98](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L98)
593
667
 
594
668
  An alternative way to compose JSX that avoids ever-increasing indentation
595
669
 
@@ -704,7 +778,7 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
704
778
  UseEventListenerWithAnyExplicitTarget;
705
779
  ```
706
780
 
707
- Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L12)
781
+ Defined in: [hooks/useEventListener.ts:13](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L13)
708
782
 
709
783
  The type of [`useEventListener`](#useeventlistener)
710
784
 
@@ -723,7 +797,7 @@ The type of [`useEventListener`](#useeventlistener)
723
797
  type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
724
798
  ```
725
799
 
726
- Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L21)
800
+ Defined in: [hooks/useEventListener.ts:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L22)
727
801
 
728
802
  ### Type Parameters
729
803
 
@@ -791,7 +865,7 @@ type UseEventListenerWithExplicitGlobalTarget =
791
865
  UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
792
866
  ```
793
867
 
794
- Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L32)
868
+ Defined in: [hooks/useEventListener.ts:33](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L33)
795
869
 
796
870
  ### See
797
871
 
@@ -808,7 +882,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
808
882
  ) => void;
809
883
  ```
810
884
 
811
- Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L44)
885
+ Defined in: [hooks/useEventListener.ts:45](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L45)
812
886
 
813
887
  ### Type Parameters
814
888
 
@@ -907,7 +981,7 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
907
981
  >;
908
982
  ```
909
983
 
910
- Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L56)
984
+ Defined in: [hooks/useEventListener.ts:57](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L57)
911
985
 
912
986
  ### See
913
987
 
@@ -928,7 +1002,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
928
1002
  : never;
929
1003
  ```
930
1004
 
931
- Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L64)
1005
+ Defined in: [hooks/useEventListener.ts:65](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L65)
932
1006
 
933
1007
  ### Type Parameters
934
1008
 
@@ -973,7 +1047,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
973
1047
  ];
974
1048
  ```
975
1049
 
976
- Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/hooks/useEventListener.ts#L78)
1050
+ Defined in: [hooks/useEventListener.ts:79](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L79)
977
1051
 
978
1052
  ### Type Parameters
979
1053
 
@@ -1017,13 +1091,13 @@ Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-esse
1017
1091
  ## ContextualizePipe
1018
1092
 
1019
1093
  ```ts
1020
- type ContextualizePipe = {
1094
+ type ContextualizePipe<Children> = {
1021
1095
  with: ContextualizeWith;
1022
- end: () => ReactNode;
1096
+ end: () => Children;
1023
1097
  };
1024
1098
  ```
1025
1099
 
1026
- Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L13)
1100
+ Defined in: [misc/contextualize.tsx:12](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L12)
1027
1101
 
1028
1102
  The return type of [`contextualize`](#contextualize)
1029
1103
 
@@ -1032,6 +1106,25 @@ The return type of [`contextualize`](#contextualize)
1032
1106
  [`contextualize`](#contextualize),
1033
1107
  [`ContextualizeWith`](#contextualizewith)
1034
1108
 
1109
+ ### Type Parameters
1110
+
1111
+ <table>
1112
+ <thead>
1113
+ <tr>
1114
+ <th>Type Parameter</th>
1115
+ </tr>
1116
+ </thead>
1117
+ <tbody>
1118
+ <tr>
1119
+ <td>
1120
+
1121
+ `Children` _extends_ `ReactNode`
1122
+
1123
+ </td>
1124
+ </tr>
1125
+ </tbody>
1126
+ </table>
1127
+
1035
1128
  ### Properties
1036
1129
 
1037
1130
  <table>
@@ -1062,7 +1155,7 @@ The return type of [`contextualize`](#contextualize)
1062
1155
  </td>
1063
1156
  <td>
1064
1157
 
1065
- () => `ReactNode`
1158
+ () => `Children`
1066
1159
 
1067
1160
  </td>
1068
1161
  </tr>
@@ -1074,10 +1167,10 @@ The return type of [`contextualize`](#contextualize)
1074
1167
  ## ContextualizeWith()
1075
1168
 
1076
1169
  ```ts
1077
- type ContextualizeWith = <T>(Context, value) => ContextualizePipe;
1170
+ type ContextualizeWith = <T>(Context, value) => ContextualizePipe<ReactElement>;
1078
1171
  ```
1079
1172
 
1080
- Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/contextualize.tsx#L23)
1173
+ Defined in: [misc/contextualize.tsx:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L22)
1081
1174
 
1082
1175
  ### Type Parameters
1083
1176
 
@@ -1137,7 +1230,7 @@ Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essenti
1137
1230
 
1138
1231
  ### Returns
1139
1232
 
1140
- [`ContextualizePipe`](#contextualizepipe)
1233
+ [`ContextualizePipe`](#contextualizepipe)\<`ReactElement`\>
1141
1234
 
1142
1235
  ### See
1143
1236
 
@@ -1155,7 +1248,7 @@ type JSXWrapPipe<Children> = {
1155
1248
  };
1156
1249
  ```
1157
1250
 
1158
- Defined in: [misc/wrapJSX.tsx:19](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L19)
1251
+ Defined in: [misc/wrapJSX.tsx:18](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L18)
1159
1252
 
1160
1253
  The return type of [`wrapJSX`](#wrapjsx)
1161
1254
 
@@ -1228,7 +1321,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1228
1321
  type WrapJSXWith<Children> = <C>(...args) => JSXWrapPipe<ReactElement>;
1229
1322
  ```
1230
1323
 
1231
- Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/blob/v0.10.5/src/misc/wrapJSX.tsx#L29)
1324
+ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L28)
1232
1325
 
1233
1326
  ### Type Parameters
1234
1327
 
@@ -1286,7 +1379,7 @@ Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/bl
1286
1379
  </td>
1287
1380
  <td>
1288
1381
 
1289
- \[`"children"` _extends_ keyof `ComponentProps`\<`C`\> ? \[`Children`\] _extends_ \[`ComponentProps`\<`C`\>\[`"children"`\]\] ? `C` : `never` : `never`, `...(Record<never, unknown> extends Omit<ComponentProps<C>, "children"> ? [props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">] : [props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">])`\]
1382
+ \[`"children"` _extends_ keyof `ComponentProps`\<`C`\> ? \[`Children`\] _extends_ \[`ComponentProps`\<`C`\>\[`"children"`\]\] ? `C` : `never` : `never`, `...(Record<never, unknown> extends Omit<ComponentProps<C>, "children"> ? [props?: JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">] : [props: JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">])`\]
1290
1383
 
1291
1384
  </td>
1292
1385
  </tr>
@@ -1,4 +1,5 @@
1
1
  export * from './useEventListener.js';
2
+ export * from './useIsomorphicLayoutEffect.js';
2
3
  export * from './useReducerWithDeps.js';
3
4
  export * from './useStateWithDeps.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from './useEventListener.js';
2
+ export * from './useIsomorphicLayoutEffect.js';
2
3
  export * from './useReducerWithDeps.js';
3
4
  export * from './useStateWithDeps.js';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useEventListener.d.ts","sourceRoot":"","sources":["../../src/hooks/useEventListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEnE;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG,wCAAwC,GACrE,wCAAwC,GACxC,qCAAqC,CAAC;AAExC;;;;GAIG;AACH,MAAM,MAAM,wCAAwC,GAAG,CACrD,CAAC,SAAS,MAAM,cAAc,EAE9B,GAAG,IAAI,EAAE,4CAA4C,CAAC,CAAC,CAAC,KACrD,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,wCAAwC,GAClD,kCAAkC,CAAC,MAAM,EAAE,cAAc,CAAC,GACxD,kCAAkC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,GAC9D,kCAAkC,CAAC,WAAW,EAAE,mBAAmB,CAAC,GACpE,kCAAkC,CAAC,UAAU,EAAE,kBAAkB,CAAC,GAClE,kCAAkC,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;AAE7E;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,CAC5C,MAAM,SAAS,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AE,gBAAgB,CAAC,EAAE,KAAK,CAAA;KAAE,CAAC,GAAG,IAAI;IAChE,SAAS,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI;IACvD,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,GAAG,SAAS;CACxD,CAAC;AAYF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAoDV,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useMemo, useRef } from 'react';
2
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
2
3
  /**
3
4
  * Adds `handler` as a listener for the event `eventName` of `target` with the
4
5
  * provided `options` applied
@@ -41,7 +42,7 @@ export const useEventListener = function useEventListener(...args) {
41
42
  : args;
42
43
  const unwrappedTarget = target && !('addEventListener' in target) ? target.current : target;
43
44
  const handlerRef = useRef(handler);
44
- useEffect(() => {
45
+ useIsomorphicLayoutEffect(() => {
45
46
  handlerRef.current = handler;
46
47
  }, [handler]);
47
48
  const { capture = false, once = false, passive, signal, } = typeof options === 'boolean' ? { capture: options } : (options ?? {});
@@ -1 +1 @@
1
- {"version":3,"file":"useEventListener.js","sourceRoot":"","sources":["../../src/hooks/useEventListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAkGnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAqB,SAAS,gBAAgB,CACzE,GAAG,IAE0C;IAE7C,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,GAMzC,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;QACzB,CAAC,CAAC,CAA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AE,OAAO,EAAE,MAAM,CAAC,CACjC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;YAC7B,8CAA8C;YAC9C,OAAO;QACT,CAAC;QAED,MAAM,QAAQ,GAAmB,UAAU,KAAK;YAC9C,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACvC,CAAC,CAAC;QAEF,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QAEvE,OAAO,GAAG,EAAE;YACV,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QAC5E,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,eAAe,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC,CAAC;AACpD,CAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type DependencyList, type EffectCallback } from 'react';
2
+ /**
3
+ * Identical to {@linkcode useLayoutEffect}, except it does not result in
4
+ * warnings when used on the server
5
+ */
6
+ export declare const useIsomorphicLayoutEffect: (effect: EffectCallback, deps?: DependencyList) => void;
7
+ //# sourceMappingURL=useIsomorphicLayoutEffect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsomorphicLayoutEffect.d.ts","sourceRoot":"","sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,CACtC,MAAM,EAAE,cAAc,EACtB,IAAI,CAAC,EAAE,cAAc,KAClB,IAAkE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { useEffect, useLayoutEffect, } from 'react';
2
+ /**
3
+ * Identical to {@linkcode useLayoutEffect}, except it does not result in
4
+ * warnings when used on the server
5
+ */
6
+ export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
7
+ //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,eAAe,GAGhB,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAG1B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC"}
@@ -4,8 +4,8 @@ export type AnyActionArg = [] | [any];
4
4
  /** @ignore */
5
5
  export type ActionDispatch<ActionArg extends AnyActionArg> = (...args: ActionArg) => void;
6
6
  /**
7
- * `useReducer` hook with an additional dependency array `deps` that resets the
8
- * state to `initialState` when dependencies change
7
+ * {@linkcode useReducer} hook with an additional dependency array `deps` that
8
+ * resets the state to `initialState` when dependencies change
9
9
  *
10
10
  * This hook is the reducer pattern counterpart of {@linkcode useStateWithDeps}.
11
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useReducerWithDeps.d.ts","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAU,MAAM,OAAO,CAAC;AAOpD,cAAc;AAEd,MAAM,MAAM,YAAY,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtC,cAAc;AACd,MAAM,MAAM,cAAc,CAAC,SAAS,SAAS,YAAY,IAAI,CAC3D,GAAG,IAAI,EAAE,SAAS,KACf,IAAI,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,YAAY,EAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,EACxC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAC5C,IAAI,EAAE,cAAc,GACnB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAYxB"}
1
+ {"version":3,"file":"useReducerWithDeps.d.ts","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,OAAO,CAAC;AAOf,cAAc;AAEd,MAAM,MAAM,YAAY,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtC,cAAc;AACd,MAAM,MAAM,cAAc,CAAC,SAAS,SAAS,YAAY,IAAI,CAC3D,GAAG,IAAI,EAAE,SAAS,KACf,IAAI,CAAC;AAEV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,YAAY,EAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,EACxC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAC5C,IAAI,EAAE,cAAc,GACnB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,CAYxB"}
@@ -1,8 +1,8 @@
1
- import { useRef } from 'react';
1
+ import { useRef, } from 'react';
2
2
  import { useStateWithDeps } from './useStateWithDeps.js';
3
3
  /**
4
- * `useReducer` hook with an additional dependency array `deps` that resets the
5
- * state to `initialState` when dependencies change
4
+ * {@linkcode useReducer} hook with an additional dependency array `deps` that
5
+ * resets the state to `initialState` when dependencies change
6
6
  *
7
7
  * This hook is the reducer pattern counterpart of {@linkcode useStateWithDeps}.
8
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useReducerWithDeps.js","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAezD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAwC,EACxC,YAA4C,EAC5C,IAAoB;IAEpB,uDAAuD;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE/D,8CAA8C;IAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnC,SAAS,QAAQ,CAAC,GAAG,IAAO;QAC1B,QAAQ,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC"}
1
+ {"version":3,"file":"useReducerWithDeps.js","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAezD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAwC,EACxC,YAA4C,EAC5C,IAAoB;IAEpB,uDAAuD;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE/D,8CAA8C;IAC9C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEnC,SAAS,QAAQ,CAAC,GAAG,IAAO;QAC1B,QAAQ,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;AAC3C,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { type DependencyList, type Dispatch, type SetStateAction } from 'react';
2
2
  /**
3
- * `useState` hook with an additional dependency array `deps` that resets the
4
- * state to `initialState` when dependencies change
3
+ * {@linkcode useState} hook with an additional dependency array `deps` that
4
+ * resets the state to `initialState` when dependencies change
5
5
  *
6
6
  * Due to React's limitations, a change in dependencies always causes two
7
7
  * renders when using this hook. The result of the first render is thrown away
@@ -1,8 +1,8 @@
1
1
  import { useState, } from 'react';
2
2
  import { depsAreEqual } from '../utils.js';
3
3
  /**
4
- * `useState` hook with an additional dependency array `deps` that resets the
5
- * state to `initialState` when dependencies change
4
+ * {@linkcode useState} hook with an additional dependency array `deps` that
5
+ * resets the state to `initialState` when dependencies change
6
6
  *
7
7
  * Due to React's limitations, a change in dependencies always causes two
8
8
  * renders when using this hook. The result of the first render is thrown away
@@ -1,4 +1,4 @@
1
- import type { Context, ReactNode } from 'react';
1
+ import type { Context, ReactElement, ReactNode } from 'react';
2
2
  /**
3
3
  * The return type of {@linkcode contextualize}
4
4
  *
@@ -6,16 +6,16 @@ import type { Context, ReactNode } from 'react';
6
6
  * {@linkcode contextualize},
7
7
  * {@linkcode ContextualizeWith}
8
8
  */
9
- export type ContextualizePipe = {
9
+ export type ContextualizePipe<Children extends ReactNode> = {
10
10
  with: ContextualizeWith;
11
- end: () => ReactNode;
11
+ end: () => Children;
12
12
  };
13
13
  /**
14
14
  * @see
15
15
  * {@linkcode contextualize},
16
16
  * {@linkcode ContextualizePipe}
17
17
  */
18
- export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => ContextualizePipe;
18
+ export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => ContextualizePipe<ReactElement>;
19
19
  /**
20
20
  * An alternative way to provide context values to component trees that avoids
21
21
  * ever-increasing indentation
@@ -67,5 +67,5 @@ export type ContextualizeWith = <T>(Context: Context<T>, value: NoInfer<T>) => C
67
67
  * @see
68
68
  * {@linkcode ContextualizePipe}
69
69
  */
70
- export declare function contextualize(children: ReactNode): ContextualizePipe;
70
+ export declare function contextualize<Children extends ReactNode>(children: Children): ContextualizePipe<Children>;
71
71
  //# sourceMappingURL=contextualize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contextualize.d.ts","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKhD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,SAAS,CAAC;CACtB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KACd,iBAAiB,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,GAAG,iBAAiB,CAWpE"}
1
+ {"version":3,"file":"contextualize.d.ts","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAI9D;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,CAAC,QAAQ,SAAS,SAAS,IAAI;IAC1D,IAAI,EAAE,iBAAiB,CAAC;IACxB,GAAG,EAAE,MAAM,QAAQ,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KACd,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,aAAa,CAAC,QAAQ,SAAS,SAAS,EACtD,QAAQ,EAAE,QAAQ,GACjB,iBAAiB,CAAC,QAAQ,CAAC,CAW7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,CAAC,QAAmB;IAC/C,OAAO;QACL,IAAI,CAAI,OAAmB,EAAE,KAAQ;YACnC,OAAO,aAAa,CAClB,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAoB,CAC9D,CAAC;QACJ,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"contextualize.js","sourceRoot":"","sources":["../../src/misc/contextualize.tsx"],"names":[],"mappings":";AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,aAAa,CAC3B,QAAkB;IAElB,OAAO;QACL,IAAI,CAAI,OAAmB,EAAE,KAAQ;YACnC,OAAO,aAAa,CAClB,KAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAoB,CAC9D,CAAC;QACJ,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,5 +1,4 @@
1
1
  import { type Context } from 'react';
2
- import type { ArgumentFallback } from '../utils.js';
3
2
  /**
4
3
  * For a given type `T`, returns a function that produces both a context of that
5
4
  * type and a hook that returns the current context value if one was provided,
@@ -56,5 +55,5 @@ import type { ArgumentFallback } from '../utils.js';
56
55
  * - ``` `use${displayName}` ``` (e.g. `useDirection`): a hook that returns the
57
56
  * current context value if one was provided, or throws an error otherwise
58
57
  */
59
- export declare function createSafeContext<T = never>(): <DisplayName extends string>(displayName: [T] extends [never] ? never : ArgumentFallback<DisplayName, never, string>) => { [K in `${DisplayName}Context`]: Context<T>; } & { [K in `use${DisplayName}`]: () => T; };
58
+ export declare function createSafeContext<T = never>(): <DisplayName extends string>(displayName: [T] extends [never] ? never : string extends DisplayName ? never : DisplayName) => { [K in `${DisplayName}Context`]: Context<T>; } & { [K in `use${DisplayName}`]: () => T; };
60
59
  //# sourceMappingURL=createSafeContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../src/misc/createSafeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAA6B,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAIpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,KAAK,MACjC,WAAW,SAAS,MAAM,EAChC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC5B,KAAK,GACL,gBAAgB,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,KAC/C,GAAG,CAAC,IAAI,GAAG,WAAW,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,GAAE,GAAG,GACjD,CAAC,IAAI,MAAM,WAAW,EAAE,GAAG,MAAM,CAAC,GACpC,CAsBF"}
1
+ {"version":3,"file":"createSafeContext.d.ts","sourceRoot":"","sources":["../../src/misc/createSafeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAA6B,MAAM,OAAO,CAAC;AAIhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,KAAK,MACjC,WAAW,SAAS,MAAM,EAChC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC5B,KAAK,GACL,MAAM,SAAS,WAAW,GACxB,KAAK,GACL,WAAW,KAChB,GAAG,CAAC,IAAI,GAAG,WAAW,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,GAAE,GAAG,GACjD,CAAC,IAAI,MAAM,WAAW,EAAE,GAAG,MAAM,CAAC,GACpC,CAsBF"}
@@ -1 +1 @@
1
- {"version":3,"file":"createSafeContext.js","sourceRoot":"","sources":["../../src/misc/createSafeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGhE,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CACL,WAEgD,EAGhD,EAAE;QACF,MAAM,WAAW,GAAG,GAAG,WAA0B,SAAkB,CAAC;QACpE,MAAM,QAAQ,GAAG,MAAM,WAA0B,EAAW,CAAC;QAE7D,MAAM,OAAO,GAAG,aAAa,CAA2B,aAAa,CAAC,CAAC;QACvE,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;QAElC,OAAO;YACL,CAAC,WAAW,CAAC,EAAE,OAAqB;YACpC,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE;gBACf,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;gBAClC,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;oBAC5B,MAAM,IAAI,KAAK,CAAC,MAAM,WAAW,qBAAqB,CAAC,CAAC;gBAC1D,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SAKF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"createSafeContext.js","sourceRoot":"","sources":["../../src/misc/createSafeContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEhE,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CACL,WAIiB,EAGjB,EAAE;QACF,MAAM,WAAW,GAAG,GAAG,WAA0B,SAAkB,CAAC;QACpE,MAAM,QAAQ,GAAG,MAAM,WAA0B,EAAW,CAAC;QAE7D,MAAM,OAAO,GAAG,aAAa,CAA2B,aAAa,CAAC,CAAC;QACvE,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;QAElC,OAAO;YACL,CAAC,WAAW,CAAC,EAAE,OAAqB;YACpC,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE;gBACf,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;gBAClC,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;oBAC5B,MAAM,IAAI,KAAK,CAAC,MAAM,WAAW,qBAAqB,CAAC,CAAC;gBAC1D,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SAKF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { ComponentProps, JSXElementConstructor, default as React, ReactElement, ReactNode } from 'react';
1
+ import type { ComponentProps, JSX, JSXElementConstructor, ReactElement, ReactNode } from 'react';
2
2
  /**
3
3
  * The return type of {@linkcode wrapJSX}
4
4
  *
@@ -18,9 +18,9 @@ export type JSXWrapPipe<Children extends ReactNode> = {
18
18
  export type WrapJSXWith<Children extends ReactNode> = <C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>>(...args: [
19
19
  Component: 'children' extends keyof ComponentProps<C> ? [Children] extends [ComponentProps<C>['children']] ? C : never : never,
20
20
  ...(Record<never, unknown> extends Omit<ComponentProps<C>, 'children'> ? [
21
- props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
21
+ props?: JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
22
22
  ] : [
23
- props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
23
+ props: JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
24
24
  ])
25
25
  ]) => JSXWrapPipe<ReactElement>;
26
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"wrapJSX.d.ts","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,OAAO,IAAI,KAAK,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,OAAO,CAAC;AAKf;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,SAAS,IAAI;IACpD,IAAI,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,QAAQ,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,SAAS,IAEhD,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,GAAG,CAAC,EACjE,GAAG,IAAI,EAAE;IACP,SAAS,EAAE,UAAU,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC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AAE;IACP,SAAS,EAAE,UAAU,SAAS,MAAM,cAAc,CAAC,CAAC,CAAC,GACjD,CAAC,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAChD,CAAC,GACD,KAAK,GACP,KAAK;IACT,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAClE;QACE,KAAK,CAAC,EAAE,GAAG,CAAC,mBAAmB,GAC7B,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;KACtC,GACD;QACE,KAAK,EAAE,GAAG,CAAC,mBAAmB,GAC5B,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC;KACtC,CAAC;CACP,KACE,WAAW,CAAC,YAAY,CAAC,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,OAAO,CAAC,QAAQ,SAAS,SAAS,EAChD,QAAQ,EAAE,QAAQ,GACjB,WAAW,CAAC,QAAQ,CAAC,CAYvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";AAiDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,OAAO,CACrB,QAAkB;IAElB,OAAO;QACL,IAAI,CACF,SAEiC,EACjC,QAAgB,EAAE;YAElB,OAAO,OAAO,CAAC,KAAC,SAAS,OAAK,KAAK,YAAG,QAAQ,GAAa,CAAC,CAAC;QAC/D,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";AAgDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,UAAU,OAAO,CACrB,QAAkB;IAElB,OAAO;QACL,IAAI,CACF,SAAsE,EACtE,QAAgB,EAAE;YAElB,OAAO,OAAO,CAAC,KAAC,SAAS,OAAK,KAAK,YAAG,QAAQ,GAAa,CAAC,CAAC;QAC/D,CAAC;QACD,GAAG;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { DependencyList } from 'react';
2
- export type ArgumentFallback<T extends Base, Default extends Base, Base = unknown> = [T] extends [never] ? Default : [Base] extends [T] ? Default : T;
3
2
  export declare function depsAreEqual(prevDeps: DependencyList, deps: DependencyList): boolean;
4
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAC1B,CAAC,SAAS,IAAI,EACd,OAAO,SAAS,IAAI,EACpB,IAAI,GAAG,OAAO,IACZ,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC;AAErE,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,cAAc,GACnB,OAAO,CAKT"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,cAAc,GACnB,OAAO,CAKT"}
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,YAAY,CAC1B,QAAwB,EACxB,IAAoB;IAEpB,OAAO,CACL,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC/B,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAC5D,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAC1B,QAAwB,EACxB,IAAoB;IAEpB,OAAO,CACL,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC/B,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAC5D,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aweebit/react-essentials",
3
- "version": "0.10.5",
3
+ "version": "0.10.7",
4
4
  "type": "module",
5
5
  "repository": "github:aweebit/react-essentials",
6
6
  "main": "dist/index.js",
@@ -28,21 +28,21 @@
28
28
  }
29
29
  },
30
30
  "devDependencies": {
31
- "@eslint/js": "^9.36.0",
32
- "@types/node": "^22.18.6",
33
- "@types/react": "^18.3.24",
34
- "eslint": "^9.36.0",
31
+ "@eslint/js": "^9.39.2",
32
+ "@types/node": "^22.19.7",
33
+ "@types/react": "^18.3.27",
34
+ "eslint": "^9.39.2",
35
35
  "eslint-config-prettier": "^10.1.8",
36
- "eslint-plugin-react-hooks": "^5.2.0",
36
+ "eslint-plugin-react-hooks": "^7.0.1",
37
37
  "husky": "^9.1.7",
38
- "lint-staged": "^16.1.6",
39
- "prettier": "3.6.2",
38
+ "lint-staged": "^16.2.7",
39
+ "prettier": "3.8.1",
40
40
  "react": "^18.3.1",
41
- "rimraf": "^6.0.1",
42
- "typedoc": "^0.28.13",
41
+ "rimraf": "^6.1.2",
42
+ "typedoc": "^0.28.16",
43
43
  "typedoc-plugin-markdown": "^4.9.0",
44
- "typescript": "~5.9.2",
45
- "typescript-eslint": "^8.44.0"
44
+ "typescript": "~5.9.3",
45
+ "typescript-eslint": "^8.53.1"
46
46
  },
47
47
  "license": "MIT"
48
48
  }
@@ -1,3 +1,4 @@
1
1
  export * from './useEventListener.js';
2
+ export * from './useIsomorphicLayoutEffect.js';
2
3
  export * from './useReducerWithDeps.js';
3
4
  export * from './useStateWithDeps.js';
@@ -1,4 +1,5 @@
1
1
  import { useEffect, useMemo, useRef, type RefObject } from 'react';
2
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
2
3
 
3
4
  /**
4
5
  * The type of {@linkcode useEventListener}
@@ -151,7 +152,7 @@ export const useEventListener: UseEventListener = function useEventListener(
151
152
  target && !('addEventListener' in target) ? target.current : target;
152
153
 
153
154
  const handlerRef = useRef(handler);
154
- useEffect(() => {
155
+ useIsomorphicLayoutEffect(() => {
155
156
  handlerRef.current = handler;
156
157
  }, [handler]);
157
158
 
@@ -0,0 +1,15 @@
1
+ import {
2
+ useEffect,
3
+ useLayoutEffect,
4
+ type DependencyList,
5
+ type EffectCallback,
6
+ } from 'react';
7
+
8
+ /**
9
+ * Identical to {@linkcode useLayoutEffect}, except it does not result in
10
+ * warnings when used on the server
11
+ */
12
+ export const useIsomorphicLayoutEffect: (
13
+ effect: EffectCallback,
14
+ deps?: DependencyList,
15
+ ) => void = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
@@ -1,4 +1,9 @@
1
- import { type DependencyList, useRef } from 'react';
1
+ import {
2
+ type DependencyList,
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ type useReducer,
5
+ useRef,
6
+ } from 'react';
2
7
  import { useStateWithDeps } from './useStateWithDeps.js';
3
8
 
4
9
  // We cannot simply import the following types from @types/react since they are
@@ -15,8 +20,8 @@ export type ActionDispatch<ActionArg extends AnyActionArg> = (
15
20
  ) => void;
16
21
 
17
22
  /**
18
- * `useReducer` hook with an additional dependency array `deps` that resets the
19
- * state to `initialState` when dependencies change
23
+ * {@linkcode useReducer} hook with an additional dependency array `deps` that
24
+ * resets the state to `initialState` when dependencies change
20
25
  *
21
26
  * This hook is the reducer pattern counterpart of {@linkcode useStateWithDeps}.
22
27
  *
@@ -7,8 +7,8 @@ import {
7
7
  import { depsAreEqual } from '../utils.js';
8
8
 
9
9
  /**
10
- * `useState` hook with an additional dependency array `deps` that resets the
11
- * state to `initialState` when dependencies change
10
+ * {@linkcode useState} hook with an additional dependency array `deps` that
11
+ * resets the state to `initialState` when dependencies change
12
12
  *
13
13
  * Due to React's limitations, a change in dependencies always causes two
14
14
  * renders when using this hook. The result of the first render is thrown away
@@ -1,5 +1,4 @@
1
- import type { Context, ReactNode } from 'react';
2
-
1
+ import type { Context, ReactElement, ReactNode } from 'react';
3
2
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
3
  import type { wrapJSX } from './wrapJSX.js';
5
4
 
@@ -10,9 +9,9 @@ import type { wrapJSX } from './wrapJSX.js';
10
9
  * {@linkcode contextualize},
11
10
  * {@linkcode ContextualizeWith}
12
11
  */
13
- export type ContextualizePipe = {
12
+ export type ContextualizePipe<Children extends ReactNode> = {
14
13
  with: ContextualizeWith;
15
- end: () => ReactNode;
14
+ end: () => Children;
16
15
  };
17
16
 
18
17
  /**
@@ -23,7 +22,7 @@ export type ContextualizePipe = {
23
22
  export type ContextualizeWith = <T>(
24
23
  Context: Context<T>,
25
24
  value: NoInfer<T>,
26
- ) => ContextualizePipe;
25
+ ) => ContextualizePipe<ReactElement>;
27
26
 
28
27
  /**
29
28
  * An alternative way to provide context values to component trees that avoids
@@ -76,7 +75,9 @@ export type ContextualizeWith = <T>(
76
75
  * @see
77
76
  * {@linkcode ContextualizePipe}
78
77
  */
79
- export function contextualize(children: ReactNode): ContextualizePipe {
78
+ export function contextualize<Children extends ReactNode>(
79
+ children: Children,
80
+ ): ContextualizePipe<Children> {
80
81
  return {
81
82
  with<T>(Context: Context<T>, value: T) {
82
83
  return contextualize(
@@ -1,5 +1,4 @@
1
1
  import { type Context, createContext, useContext } from 'react';
2
- import type { ArgumentFallback } from '../utils.js';
3
2
 
4
3
  const moValueSymbol = Symbol('noValue');
5
4
 
@@ -63,7 +62,9 @@ export function createSafeContext<T = never>() {
63
62
  return <DisplayName extends string>(
64
63
  displayName: [T] extends [never]
65
64
  ? never
66
- : ArgumentFallback<DisplayName, never, string>,
65
+ : string extends DisplayName
66
+ ? never
67
+ : DisplayName,
67
68
  ): { [K in `${DisplayName}Context`]: Context<T> } & {
68
69
  [K in `use${DisplayName}`]: () => T;
69
70
  } => {
@@ -1,11 +1,10 @@
1
1
  import type {
2
2
  ComponentProps,
3
+ JSX,
3
4
  JSXElementConstructor,
4
- default as React,
5
5
  ReactElement,
6
6
  ReactNode,
7
7
  } from 'react';
8
-
9
8
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
10
9
  import type { contextualize } from './contextualize.js';
11
10
 
@@ -37,11 +36,11 @@ export type WrapJSXWith<Children extends ReactNode> =
37
36
  : never,
38
37
  ...(Record<never, unknown> extends Omit<ComponentProps<C>, 'children'>
39
38
  ? [
40
- props?: React.JSX.IntrinsicAttributes &
39
+ props?: JSX.IntrinsicAttributes &
41
40
  Omit<ComponentProps<C>, 'children'>,
42
41
  ]
43
42
  : [
44
- props: React.JSX.IntrinsicAttributes &
43
+ props: JSX.IntrinsicAttributes &
45
44
  Omit<ComponentProps<C>, 'children'>,
46
45
  ]),
47
46
  ]
@@ -101,9 +100,7 @@ export function wrapJSX<Children extends ReactNode>(
101
100
  ): JSXWrapPipe<Children> {
102
101
  return {
103
102
  with(
104
- Component:
105
- | keyof React.JSX.IntrinsicElements
106
- | JSXElementConstructor<object>,
103
+ Component: keyof JSX.IntrinsicElements | JSXElementConstructor<object>,
107
104
  props: object = {},
108
105
  ) {
109
106
  return wrapJSX(<Component {...props}>{children}</Component>);
package/src/utils.ts CHANGED
@@ -1,11 +1,5 @@
1
1
  import type { DependencyList } from 'react';
2
2
 
3
- export type ArgumentFallback<
4
- T extends Base,
5
- Default extends Base,
6
- Base = unknown,
7
- > = [T] extends [never] ? Default : [Base] extends [T] ? Default : T;
8
-
9
3
  export function depsAreEqual(
10
4
  prevDeps: DependencyList,
11
5
  deps: DependencyList,