@aweebit/react-essentials 0.10.6 → 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.
- package/README.md +78 -23
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useEventListener.d.ts.map +1 -1
- package/dist/hooks/useEventListener.js +2 -1
- package/dist/hooks/useEventListener.js.map +1 -1
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts +7 -0
- package/dist/hooks/useIsomorphicLayoutEffect.d.ts.map +1 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js +7 -0
- package/dist/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/dist/hooks/useReducerWithDeps.d.ts +2 -2
- package/dist/hooks/useReducerWithDeps.d.ts.map +1 -1
- package/dist/hooks/useReducerWithDeps.js +3 -3
- package/dist/hooks/useReducerWithDeps.js.map +1 -1
- package/dist/hooks/useStateWithDeps.d.ts +2 -2
- package/dist/hooks/useStateWithDeps.js +2 -2
- package/dist/misc/contextualize.d.ts.map +1 -1
- package/dist/misc/contextualize.js.map +1 -1
- package/dist/misc/createSafeContext.d.ts +1 -2
- package/dist/misc/createSafeContext.d.ts.map +1 -1
- package/dist/misc/createSafeContext.js.map +1 -1
- package/dist/misc/wrapJSX.d.ts +3 -3
- package/dist/misc/wrapJSX.d.ts.map +1 -1
- package/dist/misc/wrapJSX.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +12 -12
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useEventListener.ts +2 -1
- package/src/hooks/useIsomorphicLayoutEffect.ts +15 -0
- package/src/hooks/useReducerWithDeps.ts +8 -3
- package/src/hooks/useStateWithDeps.ts +2 -2
- package/src/misc/contextualize.tsx +0 -1
- package/src/misc/createSafeContext.ts +3 -2
- package/src/misc/wrapJSX.tsx +4 -7
- package/src/utils.ts +0 -6
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](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:
|
|
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:
|
|
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
|
|
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.
|
|
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
|
|
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:
|
|
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
|
|
@@ -463,7 +518,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
|
|
|
463
518
|
};
|
|
464
519
|
```
|
|
465
520
|
|
|
466
|
-
Defined in: [misc/createSafeContext.ts:
|
|
521
|
+
Defined in: [misc/createSafeContext.ts:61](https://github.com/aweebit/react-essentials/blob/v0.10.7/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` : `
|
|
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:
|
|
666
|
+
Defined in: [misc/wrapJSX.tsx:98](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
781
|
+
Defined in: [hooks/useEventListener.ts:13](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
800
|
+
Defined in: [hooks/useEventListener.ts:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
868
|
+
Defined in: [hooks/useEventListener.ts:33](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
885
|
+
Defined in: [hooks/useEventListener.ts:45](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
984
|
+
Defined in: [hooks/useEventListener.ts:57](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
1005
|
+
Defined in: [hooks/useEventListener.ts:65](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
1050
|
+
Defined in: [hooks/useEventListener.ts:79](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
1100
|
+
Defined in: [misc/contextualize.tsx:12](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L12)
|
|
1046
1101
|
|
|
1047
1102
|
The return type of [`contextualize`](#contextualize)
|
|
1048
1103
|
|
|
@@ -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:
|
|
1173
|
+
Defined in: [misc/contextualize.tsx:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/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:
|
|
1251
|
+
Defined in: [misc/wrapJSX.tsx:18](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L18)
|
|
1197
1252
|
|
|
1198
1253
|
The return type of [`wrapJSX`](#wrapjsx)
|
|
1199
1254
|
|
|
@@ -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:
|
|
1324
|
+
Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/blob/v0.10.7/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?:
|
|
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>
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/hooks/index.js
CHANGED
package/dist/hooks/index.js.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"useEventListener.d.ts","sourceRoot":"","sources":["../../src/hooks/useEventListener.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGnE;;;;;;;;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,WAAW,EAC1B,QAAQ,IACN,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,QAAQ,EAC7C,GAAG,IAAI,EAAE,sCAAsC,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,KAC5D,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,qCAAqC,GAC/C,kCAAkC,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,MAAM,4CAA4C,CACtD,CAAC,SAAS,MAAM,cAAc,IAE9B,sCAAsC,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS;IACxE,OAAO;IACP,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
|
|
@@ -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
|
-
|
|
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;
|
|
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;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAkG3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,yBAAyB,CAAC,GAAG,EAAE;QAC7B,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,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE1E,MAAM,eAAe,GAAG,OAAO,CAC7B,GAAG,EAAE,CAAC,OAAO;IACb,uDAAuD;IACvD,CAAC,OAAO,EAAE,IAAI,EAAE,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
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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;
|
|
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":";
|
|
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 :
|
|
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;
|
|
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;
|
|
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"}
|
package/dist/misc/wrapJSX.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentProps,
|
|
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?:
|
|
21
|
+
props?: JSX.IntrinsicAttributes & Omit<ComponentProps<C>, 'children'>
|
|
22
22
|
] : [
|
|
23
|
-
props:
|
|
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,
|
|
1
|
+
{"version":3,"file":"wrapJSX.d.ts","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,GAAG,EACH,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACV,MAAM,OAAO,CAAC;AAIf;;;;;;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,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"}
|
package/dist/misc/wrapJSX.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapJSX.js","sourceRoot":"","sources":["../../src/misc/wrapJSX.tsx"],"names":[],"mappings":";
|
|
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
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -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,
|
|
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":"
|
|
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.
|
|
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.
|
|
32
|
-
"@types/node": "^22.
|
|
33
|
-
"@types/react": "^18.3.
|
|
34
|
-
"eslint": "^9.
|
|
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": "^
|
|
36
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
37
37
|
"husky": "^9.1.7",
|
|
38
|
-
"lint-staged": "^16.
|
|
39
|
-
"prettier": "3.
|
|
38
|
+
"lint-staged": "^16.2.7",
|
|
39
|
+
"prettier": "3.8.1",
|
|
40
40
|
"react": "^18.3.1",
|
|
41
|
-
"rimraf": "^6.
|
|
42
|
-
"typedoc": "^0.28.
|
|
41
|
+
"rimraf": "^6.1.2",
|
|
42
|
+
"typedoc": "^0.28.16",
|
|
43
43
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
44
|
-
"typescript": "~5.9.
|
|
45
|
-
"typescript-eslint": "^8.
|
|
44
|
+
"typescript": "~5.9.3",
|
|
45
|
+
"typescript-eslint": "^8.53.1"
|
|
46
46
|
},
|
|
47
47
|
"license": "MIT"
|
|
48
48
|
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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, 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
|
-
:
|
|
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
|
} => {
|
package/src/misc/wrapJSX.tsx
CHANGED
|
@@ -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?:
|
|
39
|
+
props?: JSX.IntrinsicAttributes &
|
|
41
40
|
Omit<ComponentProps<C>, 'children'>,
|
|
42
41
|
]
|
|
43
42
|
: [
|
|
44
|
-
props:
|
|
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,
|