@aweebit/react-essentials 0.10.6 → 0.10.8

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 (39) hide show
  1. package/README.md +82 -27
  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 +4 -3
  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 +8 -8
  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.map +1 -1
  20. package/dist/misc/contextualize.js.map +1 -1
  21. package/dist/misc/createSafeContext.d.ts +1 -2
  22. package/dist/misc/createSafeContext.d.ts.map +1 -1
  23. package/dist/misc/createSafeContext.js.map +1 -1
  24. package/dist/misc/wrapJSX.d.ts +3 -3
  25. package/dist/misc/wrapJSX.d.ts.map +1 -1
  26. package/dist/misc/wrapJSX.js.map +1 -1
  27. package/dist/utils.d.ts +0 -1
  28. package/dist/utils.d.ts.map +1 -1
  29. package/dist/utils.js.map +1 -1
  30. package/package.json +20 -14
  31. package/src/hooks/index.ts +1 -0
  32. package/src/hooks/useEventListener.ts +6 -5
  33. package/src/hooks/useIsomorphicLayoutEffect.ts +15 -0
  34. package/src/hooks/useReducerWithDeps.ts +16 -8
  35. package/src/hooks/useStateWithDeps.ts +2 -2
  36. package/src/misc/contextualize.tsx +0 -1
  37. package/src/misc/createSafeContext.ts +3 -2
  38. package/src/misc/wrapJSX.tsx +4 -7
  39. 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.6/src/hooks/useEventListener.ts#L135)
24
+ Defined in: [hooks/useEventListener.ts:136](https://github.com/aweebit/react-essentials/blob/v0.10.8/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.8/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.6/src/hooks/useReducerWithDeps.ts#L59)
129
+ Defined in: [hooks/useReducerWithDeps.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.8/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.6/src/hooks/useStateWithDeps.ts#L62)
272
+ Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.8/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
@@ -344,7 +399,7 @@ Dependencies that reset the state to `initialState`
344
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.6/src/misc/contextualize.tsx#L79)
402
+ Defined in: [misc/contextualize.tsx:78](https://github.com/aweebit/react-essentials/blob/v0.10.8/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
@@ -463,7 +518,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
463
518
  };
464
519
  ```
465
520
 
466
- Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/createSafeContext.ts#L62)
521
+ Defined in: [misc/createSafeContext.ts:61](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/createSafeContext.ts#L61)
467
522
 
468
523
  For a given type `T`, returns a function that produces both a context of that
469
524
  type and a hook that returns the current context value if one was provided,
@@ -589,7 +644,7 @@ A function that accepts a single string argument `displayName` (e.g.
589
644
  </td>
590
645
  <td>
591
646
 
592
- \[`T`\] _extends_ \[`never`\] ? `never` : `ArgumentFallback`\<`DisplayName`, `never`, `string`\>
647
+ \[`T`\] _extends_ \[`never`\] ? `never` : `string` _extends_ `DisplayName` ? `never` : `DisplayName`
593
648
 
594
649
  </td>
595
650
  </tr>
@@ -608,7 +663,7 @@ A function that accepts a single string argument `displayName` (e.g.
608
663
  function wrapJSX<Children>(children): JSXWrapPipe<Children>;
609
664
  ```
610
665
 
611
- Defined in: [misc/wrapJSX.tsx:99](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L99)
666
+ Defined in: [misc/wrapJSX.tsx:98](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L98)
612
667
 
613
668
  An alternative way to compose JSX that avoids ever-increasing indentation
614
669
 
@@ -723,7 +778,7 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
723
778
  UseEventListenerWithAnyExplicitTarget;
724
779
  ```
725
780
 
726
- Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L12)
781
+ Defined in: [hooks/useEventListener.ts:13](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L13)
727
782
 
728
783
  The type of [`useEventListener`](#useeventlistener)
729
784
 
@@ -742,7 +797,7 @@ The type of [`useEventListener`](#useeventlistener)
742
797
  type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
743
798
  ```
744
799
 
745
- Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L21)
800
+ Defined in: [hooks/useEventListener.ts:22](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L22)
746
801
 
747
802
  ### Type Parameters
748
803
 
@@ -810,7 +865,7 @@ type UseEventListenerWithExplicitGlobalTarget =
810
865
  UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
811
866
  ```
812
867
 
813
- Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L32)
868
+ Defined in: [hooks/useEventListener.ts:33](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L33)
814
869
 
815
870
  ### See
816
871
 
@@ -827,7 +882,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
827
882
  ) => void;
828
883
  ```
829
884
 
830
- Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L44)
885
+ Defined in: [hooks/useEventListener.ts:45](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L45)
831
886
 
832
887
  ### Type Parameters
833
888
 
@@ -926,7 +981,7 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
926
981
  >;
927
982
  ```
928
983
 
929
- Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L56)
984
+ Defined in: [hooks/useEventListener.ts:57](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L57)
930
985
 
931
986
  ### See
932
987
 
@@ -947,7 +1002,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
947
1002
  : never;
948
1003
  ```
949
1004
 
950
- Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L64)
1005
+ Defined in: [hooks/useEventListener.ts:65](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L65)
951
1006
 
952
1007
  ### Type Parameters
953
1008
 
@@ -992,7 +1047,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
992
1047
  ];
993
1048
  ```
994
1049
 
995
- Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/hooks/useEventListener.ts#L78)
1050
+ Defined in: [hooks/useEventListener.ts:79](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L79)
996
1051
 
997
1052
  ### Type Parameters
998
1053
 
@@ -1042,7 +1097,7 @@ type ContextualizePipe<Children> = {
1042
1097
  };
1043
1098
  ```
1044
1099
 
1045
- Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/contextualize.tsx#L13)
1100
+ Defined in: [misc/contextualize.tsx:12](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/contextualize.tsx#L12)
1046
1101
 
1047
1102
  The return type of [`contextualize`](#contextualize)
1048
1103
 
@@ -1083,7 +1138,7 @@ The return type of [`contextualize`](#contextualize)
1083
1138
  <tr>
1084
1139
  <td>
1085
1140
 
1086
- <a id="with"></a> `with`
1141
+ <a id="property-with"></a> `with`
1087
1142
 
1088
1143
  </td>
1089
1144
  <td>
@@ -1095,7 +1150,7 @@ The return type of [`contextualize`](#contextualize)
1095
1150
  <tr>
1096
1151
  <td>
1097
1152
 
1098
- <a id="end"></a> `end`
1153
+ <a id="property-end"></a> `end`
1099
1154
 
1100
1155
  </td>
1101
1156
  <td>
@@ -1115,7 +1170,7 @@ The return type of [`contextualize`](#contextualize)
1115
1170
  type ContextualizeWith = <T>(Context, value) => ContextualizePipe<ReactElement>;
1116
1171
  ```
1117
1172
 
1118
- Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/contextualize.tsx#L23)
1173
+ Defined in: [misc/contextualize.tsx:22](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/contextualize.tsx#L22)
1119
1174
 
1120
1175
  ### Type Parameters
1121
1176
 
@@ -1193,7 +1248,7 @@ type JSXWrapPipe<Children> = {
1193
1248
  };
1194
1249
  ```
1195
1250
 
1196
- Defined in: [misc/wrapJSX.tsx:19](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L19)
1251
+ Defined in: [misc/wrapJSX.tsx:18](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L18)
1197
1252
 
1198
1253
  The return type of [`wrapJSX`](#wrapjsx)
1199
1254
 
@@ -1234,7 +1289,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1234
1289
  <tr>
1235
1290
  <td>
1236
1291
 
1237
- <a id="with-1"></a> `with`
1292
+ <a id="property-with-1"></a> `with`
1238
1293
 
1239
1294
  </td>
1240
1295
  <td>
@@ -1246,7 +1301,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1246
1301
  <tr>
1247
1302
  <td>
1248
1303
 
1249
- <a id="end-1"></a> `end`
1304
+ <a id="property-end-1"></a> `end`
1250
1305
 
1251
1306
  </td>
1252
1307
  <td>
@@ -1266,7 +1321,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1266
1321
  type WrapJSXWith<Children> = <C>(...args) => JSXWrapPipe<ReactElement>;
1267
1322
  ```
1268
1323
 
1269
- Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/blob/v0.10.6/src/misc/wrapJSX.tsx#L29)
1324
+ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L28)
1270
1325
 
1271
1326
  ### Type Parameters
1272
1327
 
@@ -1324,7 +1379,7 @@ Defined in: [misc/wrapJSX.tsx:29](https://github.com/aweebit/react-essentials/bl
1324
1379
  </td>
1325
1380
  <td>
1326
1381
 
1327
- \[`"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">])`\]
1328
1383
 
1329
1384
  </td>
1330
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,Q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P,GAAG,MAAM,IAAI;CACd,GACG,IAAI,GACJ,KAAK,CAAC;AAEZ;;;GAGG;AACH,MAAM,MAAM,sCAAsC,CAChD,QAAQ,EACR,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,MAAM,QAAQ,IACtB;IACF,MAAM,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG;QAAE,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
@@ -39,9 +40,8 @@ export const useEventListener = function useEventListener(...args) {
39
40
  const [target, eventName, handler, options] = typeof args[0] === 'string'
40
41
  ? [window, ...args]
41
42
  : args;
42
- const unwrappedTarget = target && !('addEventListener' in target) ? target.current : target;
43
43
  const handlerRef = useRef(handler);
44
- useEffect(() => {
44
+ useIsomorphicLayoutEffect(() => {
45
45
  handlerRef.current = handler;
46
46
  }, [handler]);
47
47
  const { capture = false, once = false, passive, signal, } = typeof options === 'boolean' ? { capture: options } : (options ?? {});
@@ -49,6 +49,7 @@ export const useEventListener = function useEventListener(...args) {
49
49
  // eslint-disable-next-line react-hooks/exhaustive-deps
50
50
  [capture, once, passive, signal]);
51
51
  useEffect(() => {
52
+ const unwrappedTarget = target && !('addEventListener' in target) ? target.current : target;
52
53
  if (unwrappedTarget === null) {
53
54
  // No element has been attached to the ref yet
54
55
  return;
@@ -60,6 +61,6 @@ export const useEventListener = function useEventListener(...args) {
60
61
  return () => {
61
62
  unwrappedTarget.removeEventListener(eventName, listener, memoizedOptions);
62
63
  };
63
- }, [unwrappedTarget, eventName, memoizedOptions]);
64
+ }, [target, eventName, memoizedOptions]);
64
65
  };
65
66
  //# sourceMappingURL=useEventListener.js.map
@@ -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,CAAC,MAAM,EAAE,GAAI,IAAwD,CAAC;QACxE,CAAC,CAAE,IAAkD,CAAC;IAE1D,MAAM,eAAe,GACnB,MAAM,IAAI,CAAC,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAEtE,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAC/B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,MAAM,EACJ,OAAO,GAAG,KAAK,EACf,IAAI,GAAG,KAAK,EACZ,OAAO,EACP,MAAM,GACP,GAAG,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,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AAS,EAAE,eAAe,CAAC,CAAC,CAAC;AAC3C,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,CAexB"}
@@ -1,8 +1,8 @@
1
- import { useRef } from 'react';
1
+ import { useState, } 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
  *
@@ -46,10 +46,10 @@ export function useReducerWithDeps(reducer, initialState, deps) {
46
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
47
47
  const [state, setState] = useStateWithDeps(initialState, deps);
48
48
  // Only the initially provided reducer is used
49
- const reducerRef = useRef(reducer);
50
- function dispatch(...args) {
51
- setState((previousState) => reducerRef.current(previousState, ...args));
52
- }
53
- return [state, useRef(dispatch).current];
49
+ const [stableReducer] = useState(() => reducer);
50
+ const [stableDispatch] = useState(() => function dispatch(...args) {
51
+ setState((previousState) => stableReducer(previousState, ...args));
52
+ });
53
+ return [state, stableDispatch];
54
54
  }
55
55
  //# sourceMappingURL=useReducerWithDeps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useReducerWithDeps.js","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,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AAG,EAAE,CACH,SAAS,QAAQ,CAAC,GAAG,IAAO;QAC1B,QAAQ,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC,CACJ,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;AACjC,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 +1 @@
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;AAK9D;;;;;;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
+ {"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,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
+ {"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,C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AC,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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
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.6",
3
+ "version": "0.10.8",
4
4
  "type": "module",
5
5
  "repository": "github:aweebit/react-essentials",
6
6
  "main": "dist/index.js",
@@ -28,21 +28,27 @@
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": "^10.0.1",
32
+ "@types/node": "^22.19.11",
33
+ "@types/react": "^18.3.28",
34
+ "eslint": "^10.0.0",
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
+ "globals": "^17.3.0",
37
38
  "husky": "^9.1.7",
38
- "lint-staged": "^16.1.6",
39
- "prettier": "3.6.2",
39
+ "lint-staged": "^16.2.7",
40
+ "prettier": "3.8.1",
40
41
  "react": "^18.3.1",
41
- "rimraf": "^6.0.1",
42
- "typedoc": "^0.28.13",
43
- "typedoc-plugin-markdown": "^4.9.0",
44
- "typescript": "~5.9.2",
45
- "typescript-eslint": "^8.44.0"
42
+ "rimraf": "^6.1.3",
43
+ "typedoc": "^0.28.17",
44
+ "typedoc-plugin-markdown": "^4.10.0",
45
+ "typescript": "~5.9.3",
46
+ "typescript-eslint": "^8.56.0"
46
47
  },
47
- "license": "MIT"
48
+ "license": "MIT",
49
+ "overrides": {
50
+ "eslint-plugin-react-hooks": {
51
+ "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0 || ^10.0.0"
52
+ }
53
+ }
48
54
  }
@@ -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}
@@ -147,11 +148,8 @@ export const useEventListener: UseEventListener = function useEventListener(
147
148
  ? [window, ...(args as UseEventListenerWithImplicitWindowTargetArgsAny)]
148
149
  : (args as UseEventListenerWithExplicitTargetArgsAny);
149
150
 
150
- const unwrappedTarget =
151
- target && !('addEventListener' in target) ? target.current : target;
152
-
153
151
  const handlerRef = useRef(handler);
154
- useEffect(() => {
152
+ useIsomorphicLayoutEffect(() => {
155
153
  handlerRef.current = handler;
156
154
  }, [handler]);
157
155
 
@@ -169,6 +167,9 @@ export const useEventListener: UseEventListener = function useEventListener(
169
167
  );
170
168
 
171
169
  useEffect(() => {
170
+ const unwrappedTarget =
171
+ target && !('addEventListener' in target) ? target.current : target;
172
+
172
173
  if (unwrappedTarget === null) {
173
174
  // No element has been attached to the ref yet
174
175
  return;
@@ -183,5 +184,5 @@ export const useEventListener: UseEventListener = function useEventListener(
183
184
  return () => {
184
185
  unwrappedTarget.removeEventListener(eventName, listener, memoizedOptions);
185
186
  };
186
- }, [unwrappedTarget, eventName, memoizedOptions]);
187
+ }, [target, eventName, memoizedOptions]);
187
188
  } as UseEventListener;
@@ -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
+ useState,
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
  *
@@ -65,11 +70,14 @@ export function useReducerWithDeps<S, A extends AnyActionArg>(
65
70
  const [state, setState] = useStateWithDeps(initialState, deps);
66
71
 
67
72
  // Only the initially provided reducer is used
68
- const reducerRef = useRef(reducer);
73
+ const [stableReducer] = useState(() => reducer);
69
74
 
70
- function dispatch(...args: A): void {
71
- setState((previousState) => reducerRef.current(previousState, ...args));
72
- }
75
+ const [stableDispatch] = useState(
76
+ () =>
77
+ function dispatch(...args: A): void {
78
+ setState((previousState) => stableReducer(previousState, ...args));
79
+ },
80
+ );
73
81
 
74
- return [state, useRef(dispatch).current];
82
+ return [state, stableDispatch];
75
83
  }
@@ -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
1
  import type { Context, ReactElement, ReactNode } from 'react';
2
-
3
2
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
3
  import type { wrapJSX } from './wrapJSX.js';
5
4
 
@@ -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,