@yamada-ui/utils 0.1.3 → 0.1.4

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.
@@ -38,7 +38,11 @@ var createContext2 = ({
38
38
  }
39
39
  return context;
40
40
  };
41
- return [Context.Provider, useContext2, Context];
41
+ return [
42
+ Context.Provider,
43
+ useContext2,
44
+ Context
45
+ ];
42
46
  };
43
47
  var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
44
48
  var useUnmountEffect = (callback) => (
@@ -96,10 +100,13 @@ var useCallbackRef = (callback, deps = []) => {
96
100
  React.useEffect(() => {
97
101
  callbackRef.current = callback;
98
102
  });
99
- return React.useCallback((...args) => {
100
- var _a;
101
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
102
- }, deps);
103
+ return React.useCallback(
104
+ (...args) => {
105
+ var _a;
106
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
107
+ },
108
+ deps
109
+ );
103
110
  };
104
111
  var useUpdateEffect = (callback, deps) => {
105
112
  const renderCycleRef = React.useRef(false);
@@ -129,23 +136,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
129
136
  const lastCallId = React.useRef(0);
130
137
  const isMounted = useIsMounted();
131
138
  const [state, setState] = React.useState(initialState);
132
- const callback = React.useCallback((...args) => {
133
- const callId = ++lastCallId.current;
134
- if (!state.loading)
135
- setState((prevState) => ({ ...prevState, loading: true }));
136
- return func(...args).then(
137
- (value) => {
138
- if (isMounted.current && callId === lastCallId.current)
139
- setState({ value, loading: false });
140
- return value;
141
- },
142
- (error) => {
143
- if (isMounted.current && callId === lastCallId.current)
144
- setState({ error, loading: false });
145
- return error;
146
- }
147
- );
148
- }, deps);
139
+ const callback = React.useCallback(
140
+ (...args) => {
141
+ const callId = ++lastCallId.current;
142
+ if (!state.loading)
143
+ setState((prevState) => ({ ...prevState, loading: true }));
144
+ return func(...args).then(
145
+ (value) => {
146
+ if (isMounted.current && callId === lastCallId.current)
147
+ setState({ value, loading: false });
148
+ return value;
149
+ },
150
+ (error) => {
151
+ if (isMounted.current && callId === lastCallId.current)
152
+ setState({ error, loading: false });
153
+ return error;
154
+ }
155
+ );
156
+ },
157
+ // eslint-disable-next-line react-hooks/exhaustive-deps
158
+ deps
159
+ );
149
160
  return [state, callback];
150
161
  };
151
162
  var useAsyncRetry = (func, deps = []) => {
@@ -161,13 +172,16 @@ var useAsyncRetry = (func, deps = []) => {
161
172
  };
162
173
 
163
174
  // src/color.ts
164
- import { toHex, parseToRgba, transparentize, mix, darken, lighten } from "color2k";
175
+ import {
176
+ toHex,
177
+ parseToRgba,
178
+ transparentize,
179
+ mix,
180
+ darken,
181
+ lighten
182
+ } from "color2k";
165
183
  var getColor = (color, fallback) => (theme, colorMode) => {
166
- const hex = getMemoizedObject(
167
- theme,
168
- `colors.${color}`,
169
- color
170
- );
184
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
171
185
  try {
172
186
  if (isArray(hex)) {
173
187
  const [lightHex, darkHex] = hex;
@@ -211,7 +225,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
211
225
  n = n - 5 * (isLighten ? 1 : -1);
212
226
  return toHex(isLighten ? lighten(raw, n / 100) : mix(raw, "#000", n / 100));
213
227
  };
214
- var randomColor = ({ string, colors } = {}) => {
228
+ var randomColor = ({
229
+ string,
230
+ colors
231
+ } = {}) => {
215
232
  const fallback = randomHex();
216
233
  if (string && colors)
217
234
  return randomColorFromList(string, colors);
@@ -323,9 +340,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
323
340
  return obj;
324
341
  return Object.entries(obj).reduce((result, [key, value]) => {
325
342
  if (isObject(value)) {
326
- Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
327
- result[`${key}.${childKey}`] = childValue;
328
- });
343
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(
344
+ ([childKey, childValue]) => {
345
+ result[`${key}.${childKey}`] = childValue;
346
+ }
347
+ );
329
348
  } else {
330
349
  result[key] = value;
331
350
  }
@@ -56,7 +56,9 @@ var focusableElList = [
56
56
  ];
57
57
  var focusableElSelector = focusableElList.join();
58
58
  var getAllFocusable = (container) => {
59
- const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
59
+ const focusableEls = Array.from(
60
+ container.querySelectorAll(focusableElSelector)
61
+ );
60
62
  focusableEls.unshift(container);
61
63
  return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
62
64
  };
package/dist/color.d.mts CHANGED
@@ -7,7 +7,7 @@ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorM
7
7
  declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
8
8
  declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
9
9
  declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
10
- declare const randomColor: ({ string, colors }?: {
10
+ declare const randomColor: ({ string, colors, }?: {
11
11
  string?: string | undefined;
12
12
  colors?: string[] | undefined;
13
13
  }) => string;
package/dist/color.d.ts CHANGED
@@ -7,7 +7,7 @@ declare const tintColor: (color: string, amount: number) => (theme: Dict, colorM
7
7
  declare const shadeColor: (color: string, amount: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
8
8
  declare const transparentizeColor: (color: string, alpha: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
9
9
  declare const toneColor: (color: string, l: number) => (theme: Dict, colorMode: 'light' | 'dark' | undefined) => string;
10
- declare const randomColor: ({ string, colors }?: {
10
+ declare const randomColor: ({ string, colors, }?: {
11
11
  string?: string | undefined;
12
12
  colors?: string[] | undefined;
13
13
  }) => string;
package/dist/color.js CHANGED
@@ -69,11 +69,7 @@ var getMemoizedObject = memoizeObject(getObject);
69
69
 
70
70
  // src/color.ts
71
71
  var getColor = (color, fallback) => (theme, colorMode) => {
72
- const hex = getMemoizedObject(
73
- theme,
74
- `colors.${color}`,
75
- color
76
- );
72
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
77
73
  try {
78
74
  if (isArray(hex)) {
79
75
  const [lightHex, darkHex] = hex;
@@ -117,7 +113,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
117
113
  n = n - 5 * (isLighten ? 1 : -1);
118
114
  return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
119
115
  };
120
- var randomColor = ({ string, colors } = {}) => {
116
+ var randomColor = ({
117
+ string,
118
+ colors
119
+ } = {}) => {
121
120
  const fallback = randomHex();
122
121
  if (string && colors)
123
122
  return randomColorFromList(string, colors);
package/dist/color.mjs CHANGED
@@ -10,14 +10,14 @@ import {
10
10
  tintColor,
11
11
  toneColor,
12
12
  transparentizeColor
13
- } from "./chunk-UUOSA3BW.mjs";
13
+ } from "./chunk-EUA3L3L6.mjs";
14
14
  import "./chunk-SLJ4M7XC.mjs";
15
15
  import "./chunk-VYMGBE25.mjs";
16
16
  import "./chunk-BZAW2D6U.mjs";
17
17
  import "./chunk-PURW64JE.mjs";
18
18
  import "./chunk-IVGIIDMV.mjs";
19
19
  import "./chunk-R5OUKGQ5.mjs";
20
- import "./chunk-FW7XS4NH.mjs";
20
+ import "./chunk-H5VMEQNO.mjs";
21
21
  import "./chunk-PF7LRFIA.mjs";
22
22
  export {
23
23
  darkenColor,
package/dist/dom.js CHANGED
@@ -104,7 +104,9 @@ var focusableElList = [
104
104
  ];
105
105
  var focusableElSelector = focusableElList.join();
106
106
  var getAllFocusable = (container) => {
107
- const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
107
+ const focusableEls = Array.from(
108
+ container.querySelectorAll(focusableElSelector)
109
+ );
108
110
  focusableEls.unshift(container);
109
111
  return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
110
112
  };
package/dist/dom.mjs CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  isTabbable,
25
25
  platform,
26
26
  vendor
27
- } from "./chunk-FW7XS4NH.mjs";
27
+ } from "./chunk-H5VMEQNO.mjs";
28
28
  export {
29
29
  ariaAttr,
30
30
  createdDom,
package/dist/function.mjs CHANGED
@@ -3,14 +3,14 @@ import {
3
3
  handlerAll,
4
4
  noop,
5
5
  runIfFunc
6
- } from "./chunk-UUOSA3BW.mjs";
6
+ } from "./chunk-EUA3L3L6.mjs";
7
7
  import "./chunk-SLJ4M7XC.mjs";
8
8
  import "./chunk-VYMGBE25.mjs";
9
9
  import "./chunk-BZAW2D6U.mjs";
10
10
  import "./chunk-PURW64JE.mjs";
11
11
  import "./chunk-IVGIIDMV.mjs";
12
12
  import "./chunk-R5OUKGQ5.mjs";
13
- import "./chunk-FW7XS4NH.mjs";
13
+ import "./chunk-H5VMEQNO.mjs";
14
14
  import "./chunk-PF7LRFIA.mjs";
15
15
  export {
16
16
  funcAll,
package/dist/index.js CHANGED
@@ -212,9 +212,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
212
212
  return obj;
213
213
  return Object.entries(obj).reduce((result, [key, value]) => {
214
214
  if (isObject(value)) {
215
- Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
216
- result[`${key}.${childKey}`] = childValue;
217
- });
215
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(
216
+ ([childKey, childValue]) => {
217
+ result[`${key}.${childKey}`] = childValue;
218
+ }
219
+ );
218
220
  } else {
219
221
  result[key] = value;
220
222
  }
@@ -315,7 +317,11 @@ var createContext2 = ({
315
317
  }
316
318
  return context;
317
319
  };
318
- return [Context.Provider, useContext2, Context];
320
+ return [
321
+ Context.Provider,
322
+ useContext2,
323
+ Context
324
+ ];
319
325
  };
320
326
  var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
321
327
  var useUnmountEffect = (callback) => (
@@ -373,10 +379,13 @@ var useCallbackRef = (callback, deps = []) => {
373
379
  React.useEffect(() => {
374
380
  callbackRef.current = callback;
375
381
  });
376
- return React.useCallback((...args) => {
377
- var _a;
378
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
379
- }, deps);
382
+ return React.useCallback(
383
+ (...args) => {
384
+ var _a;
385
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
386
+ },
387
+ deps
388
+ );
380
389
  };
381
390
  var useUpdateEffect = (callback, deps) => {
382
391
  const renderCycleRef = React.useRef(false);
@@ -406,23 +415,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
406
415
  const lastCallId = React.useRef(0);
407
416
  const isMounted = useIsMounted();
408
417
  const [state, setState] = React.useState(initialState);
409
- const callback = React.useCallback((...args) => {
410
- const callId = ++lastCallId.current;
411
- if (!state.loading)
412
- setState((prevState) => ({ ...prevState, loading: true }));
413
- return func(...args).then(
414
- (value) => {
415
- if (isMounted.current && callId === lastCallId.current)
416
- setState({ value, loading: false });
417
- return value;
418
- },
419
- (error) => {
420
- if (isMounted.current && callId === lastCallId.current)
421
- setState({ error, loading: false });
422
- return error;
423
- }
424
- );
425
- }, deps);
418
+ const callback = React.useCallback(
419
+ (...args) => {
420
+ const callId = ++lastCallId.current;
421
+ if (!state.loading)
422
+ setState((prevState) => ({ ...prevState, loading: true }));
423
+ return func(...args).then(
424
+ (value) => {
425
+ if (isMounted.current && callId === lastCallId.current)
426
+ setState({ value, loading: false });
427
+ return value;
428
+ },
429
+ (error) => {
430
+ if (isMounted.current && callId === lastCallId.current)
431
+ setState({ error, loading: false });
432
+ return error;
433
+ }
434
+ );
435
+ },
436
+ // eslint-disable-next-line react-hooks/exhaustive-deps
437
+ deps
438
+ );
426
439
  return [state, callback];
427
440
  };
428
441
  var useAsyncRetry = (func, deps = []) => {
@@ -495,7 +508,9 @@ var focusableElList = [
495
508
  ];
496
509
  var focusableElSelector = focusableElList.join();
497
510
  var getAllFocusable = (container) => {
498
- const focusableEls = Array.from(container.querySelectorAll(focusableElSelector));
511
+ const focusableEls = Array.from(
512
+ container.querySelectorAll(focusableElSelector)
513
+ );
499
514
  focusableEls.unshift(container);
500
515
  return focusableEls.filter((el) => isFocusable(el) && isVisible(el));
501
516
  };
@@ -564,11 +579,7 @@ var calc = Object.assign(
564
579
  // src/color.ts
565
580
  var import_color2k = require("color2k");
566
581
  var getColor = (color, fallback) => (theme, colorMode) => {
567
- const hex = getMemoizedObject(
568
- theme,
569
- `colors.${color}`,
570
- color
571
- );
582
+ const hex = getMemoizedObject(theme, `colors.${color}`, color);
572
583
  try {
573
584
  if (isArray(hex)) {
574
585
  const [lightHex, darkHex] = hex;
@@ -612,7 +623,10 @@ var toneColor = (color, l) => (theme, colorMode) => {
612
623
  n = n - 5 * (isLighten ? 1 : -1);
613
624
  return (0, import_color2k.toHex)(isLighten ? (0, import_color2k.lighten)(raw, n / 100) : (0, import_color2k.mix)(raw, "#000", n / 100));
614
625
  };
615
- var randomColor = ({ string, colors } = {}) => {
626
+ var randomColor = ({
627
+ string,
628
+ colors
629
+ } = {}) => {
616
630
  const fallback = randomHex();
617
631
  if (string && colors)
618
632
  return randomColorFromList(string, colors);
package/dist/index.mjs CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  useSafeLayoutEffect,
49
49
  useUnmountEffect,
50
50
  useUpdateEffect
51
- } from "./chunk-UUOSA3BW.mjs";
51
+ } from "./chunk-EUA3L3L6.mjs";
52
52
  import "./chunk-SLJ4M7XC.mjs";
53
53
  import {
54
54
  clampNumber,
@@ -107,7 +107,7 @@ import {
107
107
  isTabbable,
108
108
  platform,
109
109
  vendor
110
- } from "./chunk-FW7XS4NH.mjs";
110
+ } from "./chunk-H5VMEQNO.mjs";
111
111
  import {
112
112
  addDomEvent,
113
113
  addPointerEvent,
package/dist/object.d.mts CHANGED
@@ -11,8 +11,8 @@ declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
11
11
  declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
12
12
  declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
13
13
  declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
14
- declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
15
- declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
14
+ declare const memoizeObject: (func: typeof getObject) => <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
15
+ declare const getMemoizedObject: <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
16
16
  declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
17
17
 
18
18
  export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject };
package/dist/object.d.ts CHANGED
@@ -11,8 +11,8 @@ declare const objectFromEntries: <T extends Dict>(entries: any[][]) => T;
11
11
  declare const keysFormObject: <T extends Dict>(obj: T) => (keyof T)[];
12
12
  declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
13
13
  declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
14
- declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
15
- declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
14
+ declare const memoizeObject: (func: typeof getObject) => <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
15
+ declare const getMemoizedObject: <T extends unknown = any>(obj: Dict, path: string | number, fallback?: any, i?: number) => T;
16
16
  declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
17
17
 
18
18
  export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject };
package/dist/object.js CHANGED
@@ -103,9 +103,11 @@ var flattenObject = (obj, maxDepth = Infinity) => {
103
103
  return obj;
104
104
  return Object.entries(obj).reduce((result, [key, value]) => {
105
105
  if (isObject(value)) {
106
- Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
107
- result[`${key}.${childKey}`] = childValue;
108
- });
106
+ Object.entries(flattenObject(value, maxDepth - 1)).forEach(
107
+ ([childKey, childValue]) => {
108
+ result[`${key}.${childKey}`] = childValue;
109
+ }
110
+ );
109
111
  } else {
110
112
  result[key] = value;
111
113
  }
package/dist/object.mjs CHANGED
@@ -13,14 +13,14 @@ import {
13
13
  pickObject,
14
14
  replaceObject,
15
15
  splitObject
16
- } from "./chunk-UUOSA3BW.mjs";
16
+ } from "./chunk-EUA3L3L6.mjs";
17
17
  import "./chunk-SLJ4M7XC.mjs";
18
18
  import "./chunk-VYMGBE25.mjs";
19
19
  import "./chunk-BZAW2D6U.mjs";
20
20
  import "./chunk-PURW64JE.mjs";
21
21
  import "./chunk-IVGIIDMV.mjs";
22
22
  import "./chunk-R5OUKGQ5.mjs";
23
- import "./chunk-FW7XS4NH.mjs";
23
+ import "./chunk-H5VMEQNO.mjs";
24
24
  import "./chunk-PF7LRFIA.mjs";
25
25
  export {
26
26
  assignAfter,
package/dist/react.d.mts CHANGED
@@ -61,10 +61,7 @@ type AsyncState<T> = {
61
61
  };
62
62
  type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
63
63
  type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
64
- type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
65
- StateFromFunctionReturningPromise<T>,
66
- T
67
- ];
64
+ type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
68
65
  declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
69
66
  type AsyncStateRetry<T> = AsyncState<T> & {
70
67
  retry(): void;
package/dist/react.d.ts CHANGED
@@ -61,10 +61,7 @@ type AsyncState<T> = {
61
61
  };
62
62
  type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
63
63
  type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
64
- type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [
65
- StateFromFunctionReturningPromise<T>,
66
- T
67
- ];
64
+ type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
68
65
  declare const useAsyncFunc: <T extends FunctionReturningPromise>(func: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => AsyncFnReturn<T>;
69
66
  type AsyncStateRetry<T> = AsyncState<T> & {
70
67
  retry(): void;
package/dist/react.js CHANGED
@@ -77,7 +77,11 @@ var createContext2 = ({
77
77
  }
78
78
  return context;
79
79
  };
80
- return [Context.Provider, useContext2, Context];
80
+ return [
81
+ Context.Provider,
82
+ useContext2,
83
+ Context
84
+ ];
81
85
  };
82
86
  var useSafeLayoutEffect = Boolean(globalThis == null ? void 0 : globalThis.document) ? React.useLayoutEffect : React.useEffect;
83
87
  var useUnmountEffect = (callback) => (
@@ -135,10 +139,13 @@ var useCallbackRef = (callback, deps = []) => {
135
139
  React.useEffect(() => {
136
140
  callbackRef.current = callback;
137
141
  });
138
- return React.useCallback((...args) => {
139
- var _a;
140
- return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
141
- }, deps);
142
+ return React.useCallback(
143
+ (...args) => {
144
+ var _a;
145
+ return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
146
+ },
147
+ deps
148
+ );
142
149
  };
143
150
  var useUpdateEffect = (callback, deps) => {
144
151
  const renderCycleRef = React.useRef(false);
@@ -168,23 +175,27 @@ var useAsyncFunc = (func, deps = [], initialState = { loading: false }) => {
168
175
  const lastCallId = React.useRef(0);
169
176
  const isMounted = useIsMounted();
170
177
  const [state, setState] = React.useState(initialState);
171
- const callback = React.useCallback((...args) => {
172
- const callId = ++lastCallId.current;
173
- if (!state.loading)
174
- setState((prevState) => ({ ...prevState, loading: true }));
175
- return func(...args).then(
176
- (value) => {
177
- if (isMounted.current && callId === lastCallId.current)
178
- setState({ value, loading: false });
179
- return value;
180
- },
181
- (error) => {
182
- if (isMounted.current && callId === lastCallId.current)
183
- setState({ error, loading: false });
184
- return error;
185
- }
186
- );
187
- }, deps);
178
+ const callback = React.useCallback(
179
+ (...args) => {
180
+ const callId = ++lastCallId.current;
181
+ if (!state.loading)
182
+ setState((prevState) => ({ ...prevState, loading: true }));
183
+ return func(...args).then(
184
+ (value) => {
185
+ if (isMounted.current && callId === lastCallId.current)
186
+ setState({ value, loading: false });
187
+ return value;
188
+ },
189
+ (error) => {
190
+ if (isMounted.current && callId === lastCallId.current)
191
+ setState({ error, loading: false });
192
+ return error;
193
+ }
194
+ );
195
+ },
196
+ // eslint-disable-next-line react-hooks/exhaustive-deps
197
+ deps
198
+ );
188
199
  return [state, callback];
189
200
  };
190
201
  var useAsyncRetry = (func, deps = []) => {
package/dist/react.mjs CHANGED
@@ -19,14 +19,14 @@ import {
19
19
  useSafeLayoutEffect,
20
20
  useUnmountEffect,
21
21
  useUpdateEffect
22
- } from "./chunk-UUOSA3BW.mjs";
22
+ } from "./chunk-EUA3L3L6.mjs";
23
23
  import "./chunk-SLJ4M7XC.mjs";
24
24
  import "./chunk-VYMGBE25.mjs";
25
25
  import "./chunk-BZAW2D6U.mjs";
26
26
  import "./chunk-PURW64JE.mjs";
27
27
  import "./chunk-IVGIIDMV.mjs";
28
28
  import "./chunk-R5OUKGQ5.mjs";
29
- import "./chunk-FW7XS4NH.mjs";
29
+ import "./chunk-H5VMEQNO.mjs";
30
30
  import "./chunk-PF7LRFIA.mjs";
31
31
  export {
32
32
  assignRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/utils",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Yamada UI utils",
5
5
  "keywords": [
6
6
  "utils",