@bouko/react 2.3.1 → 2.3.2

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.
@@ -1 +1 @@
1
- export default function useInterval(action: () => Promise<boolean | void>, delay: number): void;
1
+ export declare function useInterval(action: () => Promise<boolean | void>, delay: number, deps?: unknown[]): void;
@@ -1,11 +1,13 @@
1
1
  "use client";
2
2
  import { useEffect, useRef } from "react";
3
- export default function useInterval(action, delay) {
3
+ export function useInterval(action, delay, deps = []) {
4
4
  const ref = useRef(async () => false);
5
5
  useEffect(() => {
6
6
  ref.current = action;
7
7
  }, [action]);
8
8
  useEffect(() => {
9
+ if (deps.some(v => v === undefined || v === null))
10
+ return;
9
11
  const tick = async () => {
10
12
  const stop = await ref.current();
11
13
  if (stop && id)
@@ -14,5 +16,5 @@ export default function useInterval(action, delay) {
14
16
  const id = setInterval(tick, delay);
15
17
  tick();
16
18
  return () => clearInterval(id);
17
- }, [delay]);
19
+ }, [delay, ...deps]);
18
20
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "2.3.1",
4
+ "version": "2.3.2",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",