@versini/ui-hooks 4.1.1 → 4.1.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,18 +1,23 @@
1
- import { useState as s } from "react";
2
- function i({
3
- value: r,
4
- defaultValue: o,
5
- finalValue: l,
1
+ import { useRef as U, useState as c, useEffect as V } from "react";
2
+ function w({
3
+ value: e,
4
+ defaultValue: n,
5
+ finalValue: u,
6
6
  onChange: t = () => {
7
- }
7
+ },
8
+ initialControlledDelay: o = 0
8
9
  }) {
9
- const [c, d] = s(
10
- o !== void 0 ? o : l
11
- ), n = (e) => {
12
- d(e), t == null || t(e);
10
+ const s = U(!1), [f, i] = c(), [l, d] = c(
11
+ n !== void 0 ? n : u
12
+ ), m = (r) => {
13
+ d(r), t == null || t(r);
13
14
  };
14
- return r !== void 0 ? [r, t, !0] : [c, n, !1];
15
+ return V(() => {
16
+ (async () => e !== void 0 && (!s.current && o > 0 && (await new Promise(
17
+ (r) => setTimeout(r, o)
18
+ ), s.current = !0), i(e)))();
19
+ }, [e, o]), e !== void 0 ? [f, t, !0] : [l, m, !1];
15
20
  }
16
21
  export {
17
- i as useUncontrolled
22
+ w as useUncontrolled
18
23
  };
package/dist/index.d.ts CHANGED
@@ -110,8 +110,10 @@ interface UseUncontrolledInput<T> {
110
110
  finalValue?: T;
111
111
  /** Controlled state onChange handler */
112
112
  onChange?: (value: T) => void;
113
+ /** Initial delay for controlled state */
114
+ initialControlledDelay?: number;
113
115
  }
114
- declare function useUncontrolled<T>({ value, defaultValue, finalValue, onChange, }: UseUncontrolledInput<T>): [T, (value: T) => void, boolean];
116
+ declare function useUncontrolled<T>({ value, defaultValue, finalValue, onChange, initialControlledDelay, }: UseUncontrolledInput<T>): [T, (value: T) => void, boolean];
115
117
 
116
118
  /**
117
119
  * Hook that generates a unique id that will retain its value
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { useResizeObserver as p } from "./hooks/useResizeObserver.js";
5
5
  import { useUncontrolled as n } from "./hooks/useUncontrolled.js";
6
6
  import { useUniqueId as l } from "./hooks/useUniqueId.js";
7
7
  /*!
8
- @versini/ui-hooks v4.1.1
8
+ @versini/ui-hooks v4.1.2
9
9
  © 2024 gizmette.com
10
10
  */
11
11
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@versini/ui-hooks",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "publishConfig": {
@@ -41,5 +41,5 @@
41
41
  "react": "18.3.1",
42
42
  "react-dom": "18.3.1"
43
43
  },
44
- "gitHead": "0efa39da096a4718e375be4a7118f2e48786f401"
44
+ "gitHead": "d377204b52ba01d6b10692aabc5c0a72c0cf5d8e"
45
45
  }