@aweebit/react-essentials 0.10.7 → 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.
package/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
  const useEventListener: UseEventListener;
22
22
  ```
23
23
 
24
- Defined in: [hooks/useEventListener.ts:136](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L136)
24
+ Defined in: [hooks/useEventListener.ts:136](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L136)
25
25
 
26
26
  Adds `handler` as a listener for the event `eventName` of `target` with the
27
27
  provided `options` applied
@@ -68,7 +68,7 @@ useEventListener(buttonRef, 'click', () => console.log('click'));
68
68
  const useIsomorphicLayoutEffect: (effect, deps?) => void;
69
69
  ```
70
70
 
71
- Defined in: [hooks/useIsomorphicLayoutEffect.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useIsomorphicLayoutEffect.ts#L12)
71
+ Defined in: [hooks/useIsomorphicLayoutEffect.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useIsomorphicLayoutEffect.ts#L12)
72
72
 
73
73
  Identical to [`useLayoutEffect`](https://react.dev/reference/react/useLayoutEffect), except it does not result in
74
74
  warnings when used on the server
@@ -126,7 +126,7 @@ function useReducerWithDeps<S, A>(
126
126
  ): [S, ActionDispatch<A>];
127
127
  ```
128
128
 
129
- Defined in: [hooks/useReducerWithDeps.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useReducerWithDeps.ts#L64)
129
+ Defined in: [hooks/useReducerWithDeps.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useReducerWithDeps.ts#L64)
130
130
 
131
131
  [`useReducer`](https://react.dev/reference/react/useReducer) hook with an additional dependency array `deps` that
132
132
  resets the state to `initialState` when dependencies change
@@ -269,7 +269,7 @@ function useStateWithDeps<S>(
269
269
  ): [S, Dispatch<SetStateAction<S>>];
270
270
  ```
271
271
 
272
- Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.7/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)
273
273
 
274
274
  [`useState`](https://react.dev/reference/react/useState) hook with an additional dependency array `deps` that
275
275
  resets the state to `initialState` when dependencies change
@@ -399,7 +399,7 @@ Dependencies that reset the state to `initialState`
399
399
  function contextualize<Children>(children): ContextualizePipe<Children>;
400
400
  ```
401
401
 
402
- Defined in: [misc/contextualize.tsx:78](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L78)
402
+ Defined in: [misc/contextualize.tsx:78](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/contextualize.tsx#L78)
403
403
 
404
404
  An alternative way to provide context values to component trees that avoids
405
405
  ever-increasing indentation
@@ -518,7 +518,7 @@ function createSafeContext<T>(): <DisplayName>(displayName) => {
518
518
  };
519
519
  ```
520
520
 
521
- Defined in: [misc/createSafeContext.ts:61](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/createSafeContext.ts#L61)
521
+ Defined in: [misc/createSafeContext.ts:61](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/createSafeContext.ts#L61)
522
522
 
523
523
  For a given type `T`, returns a function that produces both a context of that
524
524
  type and a hook that returns the current context value if one was provided,
@@ -663,7 +663,7 @@ A function that accepts a single string argument `displayName` (e.g.
663
663
  function wrapJSX<Children>(children): JSXWrapPipe<Children>;
664
664
  ```
665
665
 
666
- Defined in: [misc/wrapJSX.tsx:98](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L98)
666
+ Defined in: [misc/wrapJSX.tsx:98](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L98)
667
667
 
668
668
  An alternative way to compose JSX that avoids ever-increasing indentation
669
669
 
@@ -778,7 +778,7 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
778
778
  UseEventListenerWithAnyExplicitTarget;
779
779
  ```
780
780
 
781
- Defined in: [hooks/useEventListener.ts:13](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L13)
781
+ Defined in: [hooks/useEventListener.ts:13](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L13)
782
782
 
783
783
  The type of [`useEventListener`](#useeventlistener)
784
784
 
@@ -797,7 +797,7 @@ The type of [`useEventListener`](#useeventlistener)
797
797
  type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
798
798
  ```
799
799
 
800
- Defined in: [hooks/useEventListener.ts:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L22)
800
+ Defined in: [hooks/useEventListener.ts:22](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L22)
801
801
 
802
802
  ### Type Parameters
803
803
 
@@ -865,7 +865,7 @@ type UseEventListenerWithExplicitGlobalTarget =
865
865
  UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
866
866
  ```
867
867
 
868
- Defined in: [hooks/useEventListener.ts:33](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L33)
868
+ Defined in: [hooks/useEventListener.ts:33](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L33)
869
869
 
870
870
  ### See
871
871
 
@@ -882,7 +882,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
882
882
  ) => void;
883
883
  ```
884
884
 
885
- Defined in: [hooks/useEventListener.ts:45](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L45)
885
+ Defined in: [hooks/useEventListener.ts:45](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L45)
886
886
 
887
887
  ### Type Parameters
888
888
 
@@ -981,7 +981,7 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
981
981
  >;
982
982
  ```
983
983
 
984
- Defined in: [hooks/useEventListener.ts:57](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L57)
984
+ Defined in: [hooks/useEventListener.ts:57](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L57)
985
985
 
986
986
  ### See
987
987
 
@@ -1002,7 +1002,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
1002
1002
  : never;
1003
1003
  ```
1004
1004
 
1005
- Defined in: [hooks/useEventListener.ts:65](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L65)
1005
+ Defined in: [hooks/useEventListener.ts:65](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L65)
1006
1006
 
1007
1007
  ### Type Parameters
1008
1008
 
@@ -1047,7 +1047,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
1047
1047
  ];
1048
1048
  ```
1049
1049
 
1050
- Defined in: [hooks/useEventListener.ts:79](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/hooks/useEventListener.ts#L79)
1050
+ Defined in: [hooks/useEventListener.ts:79](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/hooks/useEventListener.ts#L79)
1051
1051
 
1052
1052
  ### Type Parameters
1053
1053
 
@@ -1097,7 +1097,7 @@ type ContextualizePipe<Children> = {
1097
1097
  };
1098
1098
  ```
1099
1099
 
1100
- Defined in: [misc/contextualize.tsx:12](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L12)
1100
+ Defined in: [misc/contextualize.tsx:12](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/contextualize.tsx#L12)
1101
1101
 
1102
1102
  The return type of [`contextualize`](#contextualize)
1103
1103
 
@@ -1138,7 +1138,7 @@ The return type of [`contextualize`](#contextualize)
1138
1138
  <tr>
1139
1139
  <td>
1140
1140
 
1141
- <a id="with"></a> `with`
1141
+ <a id="property-with"></a> `with`
1142
1142
 
1143
1143
  </td>
1144
1144
  <td>
@@ -1150,7 +1150,7 @@ The return type of [`contextualize`](#contextualize)
1150
1150
  <tr>
1151
1151
  <td>
1152
1152
 
1153
- <a id="end"></a> `end`
1153
+ <a id="property-end"></a> `end`
1154
1154
 
1155
1155
  </td>
1156
1156
  <td>
@@ -1170,7 +1170,7 @@ The return type of [`contextualize`](#contextualize)
1170
1170
  type ContextualizeWith = <T>(Context, value) => ContextualizePipe<ReactElement>;
1171
1171
  ```
1172
1172
 
1173
- Defined in: [misc/contextualize.tsx:22](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/contextualize.tsx#L22)
1173
+ Defined in: [misc/contextualize.tsx:22](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/contextualize.tsx#L22)
1174
1174
 
1175
1175
  ### Type Parameters
1176
1176
 
@@ -1248,7 +1248,7 @@ type JSXWrapPipe<Children> = {
1248
1248
  };
1249
1249
  ```
1250
1250
 
1251
- Defined in: [misc/wrapJSX.tsx:18](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L18)
1251
+ Defined in: [misc/wrapJSX.tsx:18](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L18)
1252
1252
 
1253
1253
  The return type of [`wrapJSX`](#wrapjsx)
1254
1254
 
@@ -1289,7 +1289,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1289
1289
  <tr>
1290
1290
  <td>
1291
1291
 
1292
- <a id="with-1"></a> `with`
1292
+ <a id="property-with-1"></a> `with`
1293
1293
 
1294
1294
  </td>
1295
1295
  <td>
@@ -1301,7 +1301,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1301
1301
  <tr>
1302
1302
  <td>
1303
1303
 
1304
- <a id="end-1"></a> `end`
1304
+ <a id="property-end-1"></a> `end`
1305
1305
 
1306
1306
  </td>
1307
1307
  <td>
@@ -1321,7 +1321,7 @@ The return type of [`wrapJSX`](#wrapjsx)
1321
1321
  type WrapJSXWith<Children> = <C>(...args) => JSXWrapPipe<ReactElement>;
1322
1322
  ```
1323
1323
 
1324
- Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/blob/v0.10.7/src/misc/wrapJSX.tsx#L28)
1324
+ Defined in: [misc/wrapJSX.tsx:28](https://github.com/aweebit/react-essentials/blob/v0.10.8/src/misc/wrapJSX.tsx#L28)
1325
1325
 
1326
1326
  ### Type Parameters
1327
1327
 
@@ -40,7 +40,6 @@ export const useEventListener = function useEventListener(...args) {
40
40
  const [target, eventName, handler, options] = typeof args[0] === 'string'
41
41
  ? [window, ...args]
42
42
  : args;
43
- const unwrappedTarget = target && !('addEventListener' in target) ? target.current : target;
44
43
  const handlerRef = useRef(handler);
45
44
  useIsomorphicLayoutEffect(() => {
46
45
  handlerRef.current = handler;
@@ -50,6 +49,7 @@ export const useEventListener = function useEventListener(...args) {
50
49
  // eslint-disable-next-line react-hooks/exhaustive-deps
51
50
  [capture, once, passive, signal]);
52
51
  useEffect(() => {
52
+ const unwrappedTarget = target && !('addEventListener' in target) ? target.current : target;
53
53
  if (unwrappedTarget === null) {
54
54
  // No element has been attached to the ref yet
55
55
  return;
@@ -61,6 +61,6 @@ export const useEventListener = function useEventListener(...args) {
61
61
  return () => {
62
62
  unwrappedTarget.removeEventListener(eventName, listener, memoizedOptions);
63
63
  };
64
- }, [unwrappedTarget, eventName, memoizedOptions]);
64
+ }, [target, eventName, memoizedOptions]);
65
65
  };
66
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;AACnE,OAAO,EAAE,yBAAyB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,4 +1,4 @@
1
- import { useRef, } from 'react';
1
+ import { useState, } from 'react';
2
2
  import { useStateWithDeps } from './useStateWithDeps.js';
3
3
  /**
4
4
  * {@linkcode useReducer} hook with an additional dependency array `deps` that
@@ -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,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
+ {"version":3,"file":"useReducerWithDeps.js","sourceRoot":"","sources":["../../src/hooks/useReducerWithDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,QAAQ,GACT,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,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;IAEhD,MAAM,CAAC,cAAc,CAAC,GAAG,QAAQ,CAC/B,GAAG,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aweebit/react-essentials",
3
- "version": "0.10.7",
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.39.2",
32
- "@types/node": "^22.19.7",
33
- "@types/react": "^18.3.27",
34
- "eslint": "^9.39.2",
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
36
  "eslint-plugin-react-hooks": "^7.0.1",
37
+ "globals": "^17.3.0",
37
38
  "husky": "^9.1.7",
38
39
  "lint-staged": "^16.2.7",
39
40
  "prettier": "3.8.1",
40
41
  "react": "^18.3.1",
41
- "rimraf": "^6.1.2",
42
- "typedoc": "^0.28.16",
43
- "typedoc-plugin-markdown": "^4.9.0",
42
+ "rimraf": "^6.1.3",
43
+ "typedoc": "^0.28.17",
44
+ "typedoc-plugin-markdown": "^4.10.0",
44
45
  "typescript": "~5.9.3",
45
- "typescript-eslint": "^8.53.1"
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
  }
@@ -148,9 +148,6 @@ export const useEventListener: UseEventListener = function useEventListener(
148
148
  ? [window, ...(args as UseEventListenerWithImplicitWindowTargetArgsAny)]
149
149
  : (args as UseEventListenerWithExplicitTargetArgsAny);
150
150
 
151
- const unwrappedTarget =
152
- target && !('addEventListener' in target) ? target.current : target;
153
-
154
151
  const handlerRef = useRef(handler);
155
152
  useIsomorphicLayoutEffect(() => {
156
153
  handlerRef.current = handler;
@@ -170,6 +167,9 @@ export const useEventListener: UseEventListener = function useEventListener(
170
167
  );
171
168
 
172
169
  useEffect(() => {
170
+ const unwrappedTarget =
171
+ target && !('addEventListener' in target) ? target.current : target;
172
+
173
173
  if (unwrappedTarget === null) {
174
174
  // No element has been attached to the ref yet
175
175
  return;
@@ -184,5 +184,5 @@ export const useEventListener: UseEventListener = function useEventListener(
184
184
  return () => {
185
185
  unwrappedTarget.removeEventListener(eventName, listener, memoizedOptions);
186
186
  };
187
- }, [unwrappedTarget, eventName, memoizedOptions]);
187
+ }, [target, eventName, memoizedOptions]);
188
188
  } as UseEventListener;
@@ -2,7 +2,7 @@ import {
2
2
  type DependencyList,
3
3
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
4
  type useReducer,
5
- useRef,
5
+ useState,
6
6
  } from 'react';
7
7
  import { useStateWithDeps } from './useStateWithDeps.js';
8
8
 
@@ -70,11 +70,14 @@ export function useReducerWithDeps<S, A extends AnyActionArg>(
70
70
  const [state, setState] = useStateWithDeps(initialState, deps);
71
71
 
72
72
  // Only the initially provided reducer is used
73
- const reducerRef = useRef(reducer);
73
+ const [stableReducer] = useState(() => reducer);
74
74
 
75
- function dispatch(...args: A): void {
76
- setState((previousState) => reducerRef.current(previousState, ...args));
77
- }
75
+ const [stableDispatch] = useState(
76
+ () =>
77
+ function dispatch(...args: A): void {
78
+ setState((previousState) => stableReducer(previousState, ...args));
79
+ },
80
+ );
78
81
 
79
- return [state, useRef(dispatch).current];
82
+ return [state, stableDispatch];
80
83
  }