@codeleap/hooks 6.3.0 → 7.0.0

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.
Files changed (75) hide show
  1. package/dist/index.d.ts +32 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/onMount.d.ts +12 -0
  4. package/dist/onMount.d.ts.map +1 -0
  5. package/dist/onUpdate.d.ts +11 -0
  6. package/dist/onUpdate.d.ts.map +1 -0
  7. package/dist/useBooleanToggle.d.ts +10 -0
  8. package/dist/useBooleanToggle.d.ts.map +1 -0
  9. package/dist/useComponentTestId.d.ts +11 -0
  10. package/dist/useComponentTestId.d.ts.map +1 -0
  11. package/dist/useConditionalState.d.ts +21 -0
  12. package/dist/useConditionalState.d.ts.map +1 -0
  13. package/dist/useDebounce.d.ts +9 -0
  14. package/dist/useDebounce.d.ts.map +1 -0
  15. package/dist/useDebounceCallback.d.ts +18 -0
  16. package/dist/useDebounceCallback.d.ts.map +1 -0
  17. package/dist/useDerivedRef.d.ts +9 -0
  18. package/dist/useDerivedRef.d.ts.map +1 -0
  19. package/dist/useDerivedState.d.ts +17 -0
  20. package/dist/useDerivedState.d.ts.map +1 -0
  21. package/dist/useEffectOnce.d.ts +12 -0
  22. package/dist/useEffectOnce.d.ts.map +1 -0
  23. package/dist/useFilteredList.d.ts +9 -0
  24. package/dist/useFilteredList.d.ts.map +1 -0
  25. package/dist/useForceRender.d.ts +9 -0
  26. package/dist/useForceRender.d.ts.map +1 -0
  27. package/dist/useId.d.ts +9 -0
  28. package/dist/useId.d.ts.map +1 -0
  29. package/dist/useInterval.d.ts +22 -0
  30. package/dist/useInterval.d.ts.map +1 -0
  31. package/dist/useIsMounted.d.ts +24 -0
  32. package/dist/useIsMounted.d.ts.map +1 -0
  33. package/dist/useLazyStore.d.ts +10 -0
  34. package/dist/useLazyStore.d.ts.map +1 -0
  35. package/dist/useModal.d.ts +17 -0
  36. package/dist/useModal.d.ts.map +1 -0
  37. package/dist/useOptions.d.ts +15 -0
  38. package/dist/useOptions.d.ts.map +1 -0
  39. package/dist/usePartialState.d.ts +13 -0
  40. package/dist/usePartialState.d.ts.map +1 -0
  41. package/dist/usePlaces.d.ts +29 -0
  42. package/dist/usePlaces.d.ts.map +1 -0
  43. package/dist/usePlacesAutocompleteUtils.d.ts +31 -0
  44. package/dist/usePlacesAutocompleteUtils.d.ts.map +1 -0
  45. package/dist/usePrevious.d.ts +12 -0
  46. package/dist/usePrevious.d.ts.map +1 -0
  47. package/dist/usePromise.d.ts +26 -0
  48. package/dist/usePromise.d.ts.map +1 -0
  49. package/dist/useRenderCall.d.ts +3 -0
  50. package/dist/useRenderCall.d.ts.map +1 -0
  51. package/dist/useSearch/index.d.ts +36 -0
  52. package/dist/useSearch/index.d.ts.map +1 -0
  53. package/dist/useSearch/types.d.ts +17 -0
  54. package/dist/useSearch/types.d.ts.map +1 -0
  55. package/dist/useStableReference.d.ts +3 -0
  56. package/dist/useStableReference.d.ts.map +1 -0
  57. package/dist/useToggle.d.ts +10 -0
  58. package/dist/useToggle.d.ts.map +1 -0
  59. package/dist/useUncontrolled.d.ts +23 -0
  60. package/dist/useUncontrolled.d.ts.map +1 -0
  61. package/dist/useUnmount.d.ts +12 -0
  62. package/dist/useUnmount.d.ts.map +1 -0
  63. package/package.json +26 -12
  64. package/src/index.ts +2 -0
  65. package/src/useDebounce.ts +1 -1
  66. package/src/useDebounceCallback.ts +1 -1
  67. package/src/useInterval.ts +1 -1
  68. package/src/usePartialState.ts +1 -1
  69. package/src/usePlaces.ts +3 -3
  70. package/src/usePlacesAutocompleteUtils.ts +1 -1
  71. package/src/usePromise.ts +1 -1
  72. package/src/useRenderCall.ts +10 -0
  73. package/src/useStableReference.ts +15 -0
  74. package/src/useUncontrolled.ts +1 -1
  75. package/package.json.bak +0 -30
@@ -0,0 +1,32 @@
1
+ import { useEffect, useRef, useState, useImperativeHandle, useMemo, useCallback, useContext, useLayoutEffect, useDebugValue, useReducer } from 'react';
2
+ export * from './useConditionalState';
3
+ export * from './usePromise';
4
+ export * from './useUncontrolled';
5
+ export * from './useForceRender';
6
+ export * from './useDebounce';
7
+ export * from './useInterval';
8
+ export * from './onMount';
9
+ export * from './onUpdate';
10
+ export * from './usePrevious';
11
+ export * from './useToggle';
12
+ export * from './useBooleanToggle';
13
+ export * from './useModal';
14
+ export * from './usePlaces';
15
+ export * from './usePlacesAutocompleteUtils';
16
+ export * from './useEffectOnce';
17
+ export * from './useUnmount';
18
+ export * from './useSearch';
19
+ export * from './usePartialState';
20
+ export * from './useIsMounted';
21
+ export * from './useComponentTestId';
22
+ export * from './useId';
23
+ export * from './useDebounceCallback';
24
+ export * from './useDerivedRef';
25
+ export * from './useDerivedState';
26
+ export * from './useFilteredList';
27
+ export * from './useLazyStore';
28
+ export * from './useStableReference';
29
+ export * from './useOptions';
30
+ export * from './useRenderCall';
31
+ export { useEffect, useRef, useState, useImperativeHandle, useMemo, useCallback, useContext, useLayoutEffect, useDebugValue, useReducer, };
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,MAAM,EACN,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,UAAU,EACV,eAAe,EACf,aAAa,EACb,UAAU,EACX,MAAM,OAAO,CAAA;AAEd,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,sBAAsB,CAAA;AACpC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EACL,SAAS,EACT,MAAM,EACN,QAAQ,EACR,mBAAmB,EACnB,OAAO,EACP,WAAW,EACX,UAAU,EACV,eAAe,EACf,aAAa,EACb,UAAU,GACX,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { AnyFunction } from '@codeleap/types';
2
+ /**
3
+ * Hook that runs a function once when the component mounts.
4
+ *
5
+ * @example
6
+ * onMount(() => {
7
+ * console.log('Component mounted')
8
+ * return () => console.log('Component unmounted')
9
+ * })
10
+ */
11
+ export declare const onMount: (func: AnyFunction) => void;
12
+ //# sourceMappingURL=onMount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onMount.d.ts","sourceRoot":"","sources":["../src/onMount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,WAAW,SAIxC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { AnyFunction } from '@codeleap/types';
2
+ /**
3
+ * Hook that runs a function when specified dependencies change.
4
+ *
5
+ * @example
6
+ * onUpdate(() => {
7
+ * console.log('Count changed:', count)
8
+ * }, [count])
9
+ */
10
+ export declare const onUpdate: (func: AnyFunction, listeners?: never[]) => void;
11
+ //# sourceMappingURL=onUpdate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onUpdate.d.ts","sourceRoot":"","sources":["../src/onUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,WAAW,EAAE,mBAAc,SAIzD,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hook that manages a boolean state with toggle functionality.
3
+ *
4
+ * @example
5
+ * const [isOpen, toggleOpen] = useBooleanToggle(false)
6
+ * toggleOpen() // Toggles the value
7
+ * toggleOpen(true) // Sets to true
8
+ */
9
+ export declare function useBooleanToggle(initial: boolean): readonly [boolean, (value?: boolean) => void];
10
+ //# sourceMappingURL=useBooleanToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBooleanToggle.d.ts","sourceRoot":"","sources":["../src/useBooleanToggle.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,+BAGlB,OAAO,WASrC"}
@@ -0,0 +1,11 @@
1
+ import { AnyRecord } from '@codeleap/types';
2
+ /**
3
+ * Hook that generates a stable test ID for a component based on its props.
4
+ * Uses debugName if available, otherwise generates a hash from specified prop keys.
5
+ *
6
+ * @example
7
+ * const testId = useComponentTestId(Button, props, ['label', 'variant'])
8
+ * // Returns: "Button:debug-name" or "Button:123456"
9
+ */
10
+ export declare const useComponentTestId: <P extends AnyRecord>(Component: any, props: P, keys: Array<keyof P>) => string;
11
+ //# sourceMappingURL=useComponentTestId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useComponentTestId.d.ts","sourceRoot":"","sources":["../src/useComponentTestId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAmC3C;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,SAAS,EACpD,WAAW,GAAG,EACd,OAAO,CAAC,EACR,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,WAIrB,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { SetStateAction, Dispatch } from 'react';
2
+ import { AnyFunction } from '@codeleap/types';
3
+ type UseConditionalStateOptions<T> = {
4
+ initialValue?: T;
5
+ isBooleanToggle?: boolean;
6
+ };
7
+ type SetState<T> = Dispatch<SetStateAction<T>> & ((value: T) => void) & (() => void);
8
+ /**
9
+ * Hook that uses external state if provided, otherwise creates internal state.
10
+ * Useful for creating controlled/uncontrolled component patterns.
11
+ *
12
+ * @example
13
+ * // Controlled mode
14
+ * const [value, setValue] = useConditionalState(props.value, props.onChange)
15
+ *
16
+ * // Uncontrolled mode
17
+ * const [value, setValue] = useConditionalState(undefined, undefined, { initialValue: 'default' })
18
+ */
19
+ export declare const useConditionalState: <T>(value: T | undefined, setter: AnyFunction, options?: UseConditionalStateOptions<T>) => [T, SetState<T>];
20
+ export {};
21
+ //# sourceMappingURL=useConditionalState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConditionalState.d.ts","sourceRoot":"","sources":["../src/useConditionalState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,KAAK,0BAA0B,CAAC,CAAC,IAAI;IACnC,YAAY,CAAC,EAAE,CAAC,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,KAAK,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAA;AAEpF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,EACnC,OAAO,CAAC,GAAG,SAAS,EACpB,QAAQ,WAAW,EACnB,UAAS,0BAA0B,CAAC,CAAC,CAAM,KAC1C,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAUjB,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hook that debounces a value, updating it after a specified delay.
3
+ *
4
+ * @example
5
+ * const [debouncedSearch, resetDebounce] = useDebounce(searchTerm, 500)
6
+ * // debouncedSearch updates 500ms after searchTerm stops changing
7
+ */
8
+ export declare function useDebounce<T>(value: T, debounce: number): [T, () => void];
9
+ //# sourceMappingURL=useDebounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.d.ts","sourceRoot":"","sources":["../src/useDebounce.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,MAAM,GACf,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAmBjB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Hook that creates debounced, flush, and cancel functions for a callback.
3
+ *
4
+ * @example
5
+ * const { debounce, flush, cancel } = useDebounceCallback((value) => {
6
+ * console.log(value)
7
+ * }, 500)
8
+ *
9
+ * debounce('hello') // Will call callback after 500ms
10
+ * flush('immediate') // Calls callback immediately
11
+ * cancel() // Cancels pending debounced call
12
+ */
13
+ export declare function useDebounceCallback<T extends any[]>(callback: (...args: T) => void, delay?: number): {
14
+ debounce: (...args: T) => void;
15
+ flush: (...args: T) => void;
16
+ cancel: () => void;
17
+ };
18
+ //# sourceMappingURL=useDebounceCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounceCallback.d.ts","sourceRoot":"","sources":["../src/useDebounceCallback.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,GAAG,EAAE,EACjD,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EAC9B,KAAK,SAAO;wBAI2B,CAAC;qBASJ,CAAC;;EAiBtC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hook that creates a ref that automatically updates when a derived value changes.
3
+ *
4
+ * @example
5
+ * const userNameRef = useDerivedRef(user, (u) => u.name)
6
+ * // userNameRef.current will always contain the latest user name
7
+ */
8
+ export declare const useDerivedRef: <T, D>(derivedValue: D, getValue: (derivedValue: D) => T) => React.MutableRefObject<T>;
9
+ //# sourceMappingURL=useDerivedRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerivedRef.d.ts","sourceRoot":"","sources":["../src/useDerivedRef.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,EAChC,cAAc,CAAC,EACf,UAAU,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,KAC/B,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAQ1B,CAAA"}
@@ -0,0 +1,17 @@
1
+ type Options<T, D> = {
2
+ areEqual?: (currentState: T, derivedValue: D) => boolean;
3
+ transform?: (value: D | T) => any;
4
+ getValue?: (derivedValue: D) => T;
5
+ };
6
+ /**
7
+ * Hook that creates a state that synchronizes with a derived value, with customizable equality check.
8
+ *
9
+ * @example
10
+ * const [state, setState] = useDerivedState(props.value, {
11
+ * getValue: (v) => v.id,
12
+ * areEqual: (a, b) => a === b.id
13
+ * })
14
+ */
15
+ export declare const useDerivedState: <T, D = T>(derivedValue: D, options?: Options<T, D>) => [T, React.Dispatch<React.SetStateAction<T>>];
16
+ export {};
17
+ //# sourceMappingURL=useDerivedState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerivedState.d.ts","sourceRoot":"","sources":["../src/useDerivedState.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI;IACnB,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,KAAK,OAAO,CAAA;IACxD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACjC,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,CAAA;CAClC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EACtC,cAAc,CAAC,EACf,UAAS,OAAO,CAAC,CAAC,EAAE,CAAC,CAAM,KAC1B,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAoB7C,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { EffectCallback } from 'react';
2
+ /**
3
+ * Hook that runs an effect only once when the component mounts.
4
+ *
5
+ * @example
6
+ * useEffectOnce(() => {
7
+ * console.log('Runs only once on mount')
8
+ * return () => console.log('Cleanup on unmount')
9
+ * })
10
+ */
11
+ export declare const useEffectOnce: (effect: EffectCallback) => void;
12
+ //# sourceMappingURL=useEffectOnce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEffectOnce.d.ts","sourceRoot":"","sources":["../src/useEffectOnce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAa,MAAM,OAAO,CAAA;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,cAAc,SAEnD,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hook that filters out the first item from a list that matches a predicate.
3
+ *
4
+ * @example
5
+ * const filteredUsers = useFilteredList(users, (user) => user.id === deletedId)
6
+ * // Returns users array without the first user matching the predicate
7
+ */
8
+ export declare function useFilteredList<T>(list: T[], predicate: (item: T) => boolean): T[];
9
+ //# sourceMappingURL=useFilteredList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFilteredList.d.ts","sourceRoot":"","sources":["../src/useFilteredList.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAAG,CAAC,EAAE,CAWlF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hook that returns a function to force a component re-render.
3
+ *
4
+ * @example
5
+ * const forceRender = useForceRender()
6
+ * forceRender() // Forces component to re-render
7
+ */
8
+ export declare function useForceRender(): import("react").ActionDispatch<[]>;
9
+ //# sourceMappingURL=useForceRender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForceRender.d.ts","sourceRoot":"","sources":["../src/useForceRender.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,cAAc,uCAG7B"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Hook that returns a stable ID, using provided ID if available or generating one.
3
+ *
4
+ * @example
5
+ * const id = useId('custom-id') // Returns 'custom-id'
6
+ * const id = useId() // Returns generated ID like ':r1:'
7
+ */
8
+ export declare function useId<T>(id?: T): string | NonNullable<T>;
9
+ //# sourceMappingURL=useId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useId.d.ts","sourceRoot":"","sources":["../src/useId.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,2BAK9B"}
@@ -0,0 +1,22 @@
1
+ import { AnyFunction } from '@codeleap/types';
2
+ type UseIntervalHandler = (clear: AnyFunction) => void;
3
+ /**
4
+ * Hook that manages an interval with start and clear controls.
5
+ * The handler receives a clear function to stop the interval from within.
6
+ *
7
+ * @example
8
+ * const { start, clear } = useInterval((clearFn) => {
9
+ * console.log('Tick')
10
+ * if (shouldStop) clearFn()
11
+ * }, 1000)
12
+ *
13
+ * start() // Starts the interval
14
+ * clear() // Stops the interval
15
+ */
16
+ export declare function useInterval(handler: UseIntervalHandler, interval: number): {
17
+ clear: () => void;
18
+ start: () => void;
19
+ interval: number | null;
20
+ };
21
+ export {};
22
+ //# sourceMappingURL=useInterval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../src/useInterval.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,KAAK,kBAAkB,GAAG,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAA;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM;;;;EAoCxE"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Hook to check if the component has mounted. SSR safe.
3
+ *
4
+ * @example
5
+ * const isMounted = useIsMounted()
6
+ * if (isMounted) {
7
+ * // Safe to use browser APIs
8
+ * }
9
+ */
10
+ export declare function useIsMounted(): boolean;
11
+ /**
12
+ * Hook to check if the code is running on the client-side.
13
+ * NOTE: This is just a mirror of `useIsMounted` for retrocompatibility reasons
14
+ *
15
+ * @example
16
+ * const { isClient } = useIsClient()
17
+ * if (isClient) {
18
+ * // Safe to use browser APIs
19
+ * }
20
+ */
21
+ export declare function useIsClient(): {
22
+ isClient: boolean;
23
+ };
24
+ //# sourceMappingURL=useIsMounted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIsMounted.d.ts","sourceRoot":"","sources":["../src/useIsMounted.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,wBAAgB,YAAY,YAQ3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW;;EAI1B"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hook that lazily creates a global store with an initial value.
3
+ * The store is created only once and persists across re-renders.
4
+ *
5
+ * @example
6
+ * const counterStore = useLazyStore(0)
7
+ * // Store is created once and can be used across components
8
+ */
9
+ export declare function useLazyStore<T>(initialValue: T): import("@codeleap/store").GlobalState<T>;
10
+ //# sourceMappingURL=useLazyStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyStore.d.ts","sourceRoot":"","sources":["../src/useLazyStore.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,4CAM9C"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Hook that manages modal visibility state with open, close, and toggle functions.
3
+ *
4
+ * @example
5
+ * const modal = useModal()
6
+ * modal.open() // Opens modal
7
+ * modal.close() // Closes modal
8
+ * modal.toggle() // Toggles visibility
9
+ * modal.toggle(true) // Forces open
10
+ */
11
+ export declare function useModal(startsOpen?: boolean): {
12
+ visible: boolean;
13
+ toggle: (forceVisible?: boolean) => void;
14
+ open: () => void;
15
+ close: () => void;
16
+ };
17
+ //# sourceMappingURL=useModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../src/useModal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,UAAU,UAAQ;;4BAWV,OAAO;;;EAUvC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Hook that manages selected option state with boolean flags for each option.
3
+ *
4
+ * @example
5
+ * const { selectedOption, setSelectedOption, isSelected } = useOptions(['light', 'dark'] as const)
6
+ * // isSelected = { light: true, dark: false }
7
+ * setSelectedOption('dark')
8
+ * // isSelected = { light: false, dark: true }
9
+ */
10
+ export declare function useOptions<T extends string>(options: readonly T[], initialOptions?: T): {
11
+ selectedOption: T;
12
+ setSelectedOption: import("react").Dispatch<import("react").SetStateAction<T>>;
13
+ isSelected: Record<T, boolean>;
14
+ };
15
+ //# sourceMappingURL=useOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptions.d.ts","sourceRoot":"","sources":["../src/useOptions.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,cAAc,GAAE,CAAc;;;;EAejG"}
@@ -0,0 +1,13 @@
1
+ import { DeepPartial } from '@codeleap/types';
2
+ type SetPartialStateCallback<T> = (value: T) => DeepPartial<T>;
3
+ /**
4
+ * Hook that manages state with partial updates using deep merge.
5
+ *
6
+ * @example
7
+ * const [user, setUser] = usePartialState({ name: 'John', age: 30 })
8
+ * setUser({ age: 31 }) // Only updates age, keeps name
9
+ * setUser(prev => ({ age: prev.age + 1 })) // Functional update
10
+ */
11
+ export declare function usePartialState<T extends object = any>(initial: T | (() => T)): readonly [T, (value: DeepPartial<T> | SetPartialStateCallback<T>) => void];
12
+ export {};
13
+ //# sourceMappingURL=usePartialState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePartialState.d.ts","sourceRoot":"","sources":["../src/usePartialState.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,KAAK,uBAAuB,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,CAAA;AAE9D;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,wBAInE,WAAW,CAAC,CAAC,CAAC,GAAG,uBAAuB,CAAC,CAAC,CAAC,WAUrD"}
@@ -0,0 +1,29 @@
1
+ type Params = {
2
+ input?: string;
3
+ key?: string;
4
+ showDetails?: boolean;
5
+ };
6
+ /**
7
+ * Retrieves detailed information for a specific Google Place.
8
+ */
9
+ export declare const retrievePlaceDetails: (placeId: string, apiKey: string) => Promise<any>;
10
+ /**
11
+ * Retrieves places from Google Places API or Geocoding API.
12
+ * Supports both text search and lat/lng coordinates.
13
+ */
14
+ export declare const retrievePlaces: (params: Params) => Promise<any>;
15
+ export type UsePlacesParams = Params;
16
+ /**
17
+ * Hook that fetches Google Places using React Query.
18
+ * Automatically handles caching and refetching.
19
+ *
20
+ * @example
21
+ * const places = usePlaces({
22
+ * input: 'New York',
23
+ * key: 'YOUR_API_KEY',
24
+ * showDetails: true
25
+ * })
26
+ */
27
+ export declare const usePlaces: (params: Params) => import("@tanstack/react-query").UseQueryResult<any, Error>;
28
+ export {};
29
+ //# sourceMappingURL=usePlaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaces.d.ts","sourceRoot":"","sources":["../src/usePlaces.ts"],"names":[],"mappings":"AASA,KAAK,MAAM,GAAG;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAU,SAAS,MAAM,EAAE,QAAQ,MAAM,iBASzE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,QAAQ,MAAM,iBAyBlD,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,MAAM,CAAA;AAEpC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,+DAOvC,CAAA"}
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export type UsePlacesAutocompleteUtilsProps<T extends Record<string, any>> = {
3
+ debounce?: number;
4
+ onValueChange?: (address: string) => void;
5
+ onPress?: (address: string, item: T) => void;
6
+ };
7
+ /**
8
+ * Hook that manages address autocomplete state with debounced input handling.
9
+ * Useful for Google Places autocomplete implementations.
10
+ *
11
+ * @example
12
+ * const {
13
+ * address,
14
+ * handleChangeAddress,
15
+ * handlePressAddress,
16
+ * isTyping
17
+ * } = usePlacesAutocompleteUtils({
18
+ * debounce: 500,
19
+ * onValueChange: (addr) => fetchPlaces(addr),
20
+ * onPress: (addr, item) => console.log('Selected:', item)
21
+ * })
22
+ */
23
+ export declare const usePlacesAutocompleteUtils: <T extends Record<string, any>>(props: UsePlacesAutocompleteUtilsProps<T>) => {
24
+ handleChangeAddress: (address: string) => void;
25
+ handlePressAddress: (address: string, item: T) => void;
26
+ handleClearAddress: () => void;
27
+ address: string;
28
+ isTyping: boolean;
29
+ setIsTyping: React.Dispatch<React.SetStateAction<boolean>>;
30
+ };
31
+ //# sourceMappingURL=usePlacesAutocompleteUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlacesAutocompleteUtils.d.ts","sourceRoot":"","sources":["../src/usePlacesAutocompleteUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,MAAM,+BAA+B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;CAC7C,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,+BAA+B,CAAC,CAAC,CAAC;mCAY3E,MAAM;kCAmBP,MAAM,QAAQ,CAAC;;;;;CAkBrD,CAAA"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hook that returns the previous value of a variable.
3
+ * The value is updated after render is committed to the DOM.
4
+ *
5
+ * @example
6
+ * const [count, setCount] = useState(0)
7
+ * const prevCount = usePrevious(count)
8
+ * // On first render: count=0, prevCount=null
9
+ * // After setCount(1): count=1, prevCount=0
10
+ */
11
+ export declare const usePrevious: <T>(value: T) => T | null;
12
+ //# sourceMappingURL=usePrevious.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrevious.d.ts","sourceRoot":"","sources":["../src/usePrevious.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,CAAC,aAMtC,CAAA"}
@@ -0,0 +1,26 @@
1
+ type UsePromiseOptions<T = any> = {
2
+ onResolve?: (value: T) => void;
3
+ onReject?: (err: any) => void;
4
+ timeout?: number;
5
+ debugName?: string;
6
+ };
7
+ /**
8
+ * Hook that creates a deferred promise with manual resolve/reject control.
9
+ * Useful for coordinating asynchronous operations across component lifecycle.
10
+ *
11
+ * @example
12
+ * const promise = usePromise({ timeout: 5000 })
13
+ * const handleClick = async () => {
14
+ * const result = await promise._await()
15
+ * console.log(result)
16
+ * }
17
+ * // Later, from another callback:
18
+ * promise.resolve('success')
19
+ */
20
+ export declare const usePromise: <T = any>(options?: UsePromiseOptions<T>) => {
21
+ _await: () => Promise<T>;
22
+ resolve: (value: T) => Promise<void>;
23
+ reject: (err: any) => Promise<void>;
24
+ };
25
+ export {};
26
+ //# sourceMappingURL=usePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../src/usePromise.ts"],"names":[],"mappings":"AAGA,KAAK,iBAAiB,CAAC,CAAC,GAAG,GAAG,IAAI;IAChC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAA;IAC9B,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,GAAG,EAAE,UAAU,iBAAiB,CAAC,CAAC,CAAC;;qBAYlC,CAAC;kBAPJ,GAAG;CA+B/B,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Calls `fn` synchronously during render, capped at `maxRunCount` renders (default 1). Does not use effects — execution happens inline during the render phase. */
2
+ export declare function useRenderCall(fn: () => void, maxRunCount?: number): void;
3
+ //# sourceMappingURL=useRenderCall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRenderCall.d.ts","sourceRoot":"","sources":["../src/useRenderCall.ts"],"names":[],"mappings":"AAEA,oKAAoK;AACpK,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,WAAW,SAAI,QAM5D"}
@@ -0,0 +1,36 @@
1
+ import { useSearchParams } from './types';
2
+ /**
3
+ * Hook that manages searchable select/autocomplete state with async loading support.
4
+ * Handles both local filtering and remote data fetching.
5
+ *
6
+ * @example
7
+ * const search = useSearch({
8
+ * value: 'selected-value',
9
+ * multiple: false,
10
+ * defaultOptions: [...],
11
+ * loadOptions: async (query) => fetchOptions(query),
12
+ * filterItems: (query, opts) => opts.filter(o => o.label.includes(query))
13
+ * })
14
+ *
15
+ * search.onChangeSearch('query')
16
+ * search.load()
17
+ */
18
+ export declare function useSearch<T extends string | number = string, Multi extends boolean = false>(props: useSearchParams<T, Multi>): {
19
+ loading: boolean;
20
+ setLoading: (value?: boolean) => void;
21
+ labelOptions: {
22
+ label: any;
23
+ value: T;
24
+ }[];
25
+ setLabelOptions: import("react").Dispatch<import("react").SetStateAction<{
26
+ label: any;
27
+ value: T;
28
+ }[]>>;
29
+ filteredOptions: {
30
+ label: any;
31
+ value: T;
32
+ }[];
33
+ load: () => Promise<void>;
34
+ onChangeSearch: (searchValue: string) => Promise<void>;
35
+ };
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useSearch/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAGzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAC,MAAM,GAAG,MAAM,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC;;;;;;;;;;;;;;;;kCA2C/E,MAAM;EAsBjD"}
@@ -0,0 +1,17 @@
1
+ export type AutocompleteValue<T, Multi extends boolean = false> = Multi extends true ? T[] : T;
2
+ type Options<T> = {
3
+ label: any;
4
+ value: T;
5
+ }[];
6
+ export type useSearchParams<T, Multi extends boolean = false> = {
7
+ value: AutocompleteValue<T, Multi>;
8
+ multiple: Multi;
9
+ options: Options<T>;
10
+ filterItems: (search: string, items: Options<T>) => Options<T>;
11
+ debugName: string;
12
+ defaultOptions: Options<T>;
13
+ loadOptions: (search: string) => Promise<Options<T>>;
14
+ onLoadOptionsError: (error: any) => void;
15
+ };
16
+ export {};
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/useSearch/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,IAAI,KAAK,SAAS,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;AAE9F,KAAK,OAAO,CAAC,CAAC,IAAI;IAAE,KAAK,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,EAAE,CAAA;AAE5C,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,KAAK,SAAS,OAAO,GAAG,KAAK,IAAI;IAC9D,KAAK,EAAE,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IAClC,QAAQ,EAAC,KAAK,CAAA;IACd,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACnB,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;IAC9D,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAC1B,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,kBAAkB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAA;CACzC,CAAA"}
@@ -0,0 +1,3 @@
1
+ /** Returns the previous ref value when the object is deeply equal to the last render, preventing unnecessary re-renders caused by referential inequality. */
2
+ export declare function useStableReference<T extends Record<string, any>>(value: T): T;
3
+ //# sourceMappingURL=useStableReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useStableReference.d.ts","sourceRoot":"","sources":["../src/useStableReference.ts"],"names":[],"mappings":"AAGA,6JAA6J;AAC7J,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,KAUzE"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hook that toggles between two values.
3
+ *
4
+ * @example
5
+ * const [theme, toggleTheme] = useToggle(['light', 'dark'] as const, 'light')
6
+ * toggleTheme() // Switches to 'dark'
7
+ * toggleTheme('light') // Sets to 'light'
8
+ */
9
+ export declare function useToggle<T extends readonly [any, any], V extends T[0] | T[1]>(options: T, initial: V): readonly [V, (newValue?: V) => void];
10
+ //# sourceMappingURL=useToggle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToggle.d.ts","sourceRoot":"","sources":["../src/useToggle.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAC5E,OAAO,EAAE,CAAC,EACV,OAAO,EAAE,CAAC,4BAI2B,CAAC,WAOvC"}
@@ -0,0 +1,23 @@
1
+ export type UncontrolledMode = 'initial' | 'controlled' | 'uncontrolled';
2
+ export interface UncontrolledOptions<T> {
3
+ value: T | null | undefined;
4
+ defaultValue: T | null | undefined;
5
+ finalValue: T | null;
6
+ onChange(value: T | null): void;
7
+ onValueUpdate?(value: T | null): void;
8
+ rule: (value: T | null | undefined) => boolean;
9
+ }
10
+ /**
11
+ * Hook that manages controlled/uncontrolled component pattern with smooth transitions.
12
+ *
13
+ * @example
14
+ * const [value, handleChange, mode] = useUncontrolled({
15
+ * value: props.value,
16
+ * defaultValue: 'default',
17
+ * finalValue: '',
18
+ * rule: (v) => v !== undefined,
19
+ * onChange: (v) => props.onChange?.(v)
20
+ * })
21
+ */
22
+ export declare function useUncontrolled<T>({ value, defaultValue, finalValue, rule, onChange, onValueUpdate, }: UncontrolledOptions<T>): readonly [T | null, (nextValue: T | null) => void, UncontrolledMode];
23
+ //# sourceMappingURL=useUncontrolled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUncontrolled.d.ts","sourceRoot":"","sources":["../src/useUncontrolled.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,YAAY,GAAG,cAAc,CAAA;AAExE,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IAC3B,YAAY,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,CAAA;IAClC,UAAU,EAAE,CAAC,GAAG,IAAI,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;IAC/B,aAAa,CAAC,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;IACrC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,OAAO,CAAA;CAC/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,KAAK,EACL,YAAY,EACZ,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,aAAa,GACd,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,EAAE,gBAAgB,CAAC,CAgD/F"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hook that runs a cleanup function when the component unmounts.
3
+ * The function reference is updated on each render to always use the latest version.
4
+ *
5
+ * @example
6
+ * useUnmount(() => {
7
+ * console.log('Component unmounting')
8
+ * // Cleanup logic here
9
+ * })
10
+ */
11
+ export declare const useUnmount: (fn: () => any) => void;
12
+ //# sourceMappingURL=useUnmount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnmount.d.ts","sourceRoot":"","sources":["../src/useUnmount.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,GAAI,IAAI,MAAM,GAAG,KAAG,IAO1C,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "@codeleap/hooks",
3
- "version": "6.3.0",
3
+ "version": "7.0.0",
4
4
  "main": "src/index.ts",
5
+ "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "source": "./src/index.ts",
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src"
17
+ ],
5
18
  "license": "UNLICENSED",
6
19
  "repository": {
7
20
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -9,22 +22,23 @@
9
22
  "directory": "packages/hooks"
10
23
  },
11
24
  "devDependencies": {
12
- "@codeleap/config": "6.3.0",
13
- "@codeleap/types": "6.3.0",
14
- "@codeleap/utils": "6.3.0",
15
- "@codeleap/logger": "6.3.0",
25
+ "@codeleap/config": "7.0.0",
26
+ "@codeleap/types": "7.0.0",
27
+ "@codeleap/utils": "7.0.0",
28
+ "@codeleap/logger": "7.0.0",
16
29
  "ts-node-dev": "1.1.8"
17
30
  },
18
31
  "scripts": {
19
- "build": "echo 'No build needed'"
32
+ "build": "tsc --build tsconfig.build.json",
33
+ "typecheck": "bun tsc --noEmit -p ./tsconfig.json"
20
34
  },
21
35
  "peerDependencies": {
22
- "@codeleap/types": "6.3.0",
23
- "@codeleap/utils": "6.3.0",
24
- "@codeleap/logger": "6.3.0",
36
+ "@codeleap/types": "7.0.0",
37
+ "@codeleap/utils": "7.0.0",
38
+ "@codeleap/logger": "7.0.0",
25
39
  "axios": "^1.7.9",
26
- "typescript": "5.5.2",
40
+ "typescript": "6.0.3",
27
41
  "react": "19.1.0",
28
- "@tanstack/react-query": "5.89.0"
42
+ "@tanstack/react-query": "5.100.9"
29
43
  }
30
- }
44
+ }
package/src/index.ts CHANGED
@@ -37,7 +37,9 @@ export * from './useDerivedRef'
37
37
  export * from './useDerivedState'
38
38
  export * from './useFilteredList'
39
39
  export * from './useLazyStore'
40
+ export * from './useStableReference'
40
41
  export * from './useOptions'
42
+ export * from './useRenderCall'
41
43
 
42
44
  export {
43
45
  useEffect,
@@ -13,7 +13,7 @@ export function useDebounce<T>(
13
13
  ): [T, () => void] {
14
14
  const [debouncedValue, setDebouncedValue] = useState(value)
15
15
 
16
- const timeoutRef = useRef(null)
16
+ const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
17
17
 
18
18
  const reset = () => {
19
19
  if (timeoutRef.current) {
@@ -16,7 +16,7 @@ export function useDebounceCallback<T extends any[]>(
16
16
  callback: (...args: T) => void,
17
17
  delay = 1000,
18
18
  ) {
19
- const timeoutRef = useRef(null)
19
+ const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
20
20
 
21
21
  const debounce = useCallback((...args: T) => {
22
22
  cancel()
@@ -17,7 +17,7 @@ type UseIntervalHandler = (clear: AnyFunction) => void
17
17
  * clear() // Stops the interval
18
18
  */
19
19
  export function useInterval(handler: UseIntervalHandler, interval: number) {
20
- const intervalRef = useRef<NodeJS.Timer | null>(null)
20
+ const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null)
21
21
  const handlerRef = useRef<UseIntervalHandler>(handler)
22
22
 
23
23
  useEffect(() => {
@@ -12,7 +12,7 @@ type SetPartialStateCallback<T> = (value: T) => DeepPartial<T>
12
12
  * setUser({ age: 31 }) // Only updates age, keeps name
13
13
  * setUser(prev => ({ age: prev.age + 1 })) // Functional update
14
14
  */
15
- export function usePartialState<T= any>(initial: T | (() => T)) {
15
+ export function usePartialState<T extends object = any>(initial: T | (() => T)) {
16
16
  const [state, setState] = useState(initial)
17
17
 
18
18
  function setPartial(
package/src/usePlaces.ts CHANGED
@@ -33,7 +33,7 @@ export const retrievePlaceDetails = async (placeId: string, apiKey: string) => {
33
33
  */
34
34
  export const retrievePlaces = async (params: Params) => {
35
35
  let response
36
- const inputWithoutSpaces = params?.input?.replace(/\s/g, '')
36
+ const inputWithoutSpaces = params?.input?.replace(/\s/g, '') ?? ''
37
37
  const isLatLng = latLngRegex?.test(inputWithoutSpaces)
38
38
 
39
39
  if (isLatLng) {
@@ -45,9 +45,9 @@ export const retrievePlaces = async (params: Params) => {
45
45
  let places = response?.data?.results || response?.data?.predictions
46
46
 
47
47
  if (params?.showDetails) {
48
- const apiKey = params?.key
48
+ const apiKey = params?.key ?? ''
49
49
  places = await Promise.all(
50
- places?.map(async (place) => {
50
+ places?.map(async (place: any) => {
51
51
  const placeId = place?.place_id
52
52
  const details = await retrievePlaceDetails(placeId, apiKey)
53
53
  return { ...place, details }
@@ -33,7 +33,7 @@ export const usePlacesAutocompleteUtils = <T extends Record<string, any>>(props:
33
33
  const [address, setAddress] = React.useState('')
34
34
  const [isTyping, setIsTyping] = React.useState(false)
35
35
 
36
- const setSearchTimeout = React.useRef<NodeJS.Timer | null>(null)
36
+ const setSearchTimeout = React.useRef<ReturnType<typeof setTimeout> | null>(null)
37
37
 
38
38
  const handleChangeAddress = (address: string) => {
39
39
  setAddress(address)
package/src/usePromise.ts CHANGED
@@ -24,7 +24,7 @@ type UsePromiseOptions<T = any> = {
24
24
  export const usePromise = <T = any>(options?: UsePromiseOptions<T>) => {
25
25
  const rejectRef = useRef<AnyFunction>(null)
26
26
  const resolveRef = useRef<(v:T) => any>(null)
27
- const timeoutRef = useRef(null)
27
+ const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
28
28
 
29
29
  const reject = async (err: any) => {
30
30
  await rejectRef.current?.(err)
@@ -0,0 +1,10 @@
1
+ import { useRef } from 'react'
2
+
3
+ /** Calls `fn` synchronously during render, capped at `maxRunCount` renders (default 1). Does not use effects — execution happens inline during the render phase. */
4
+ export function useRenderCall(fn: () => void, maxRunCount = 1) {
5
+ const callCount = useRef(0)
6
+ if (callCount.current < maxRunCount) {
7
+ callCount.current++
8
+ fn()
9
+ }
10
+ }
@@ -0,0 +1,15 @@
1
+ import { deepEqual } from '@codeleap/utils'
2
+ import { useRef } from 'react'
3
+
4
+ /** Returns the previous ref value when the object is deeply equal to the last render, preventing unnecessary re-renders caused by referential inequality. */
5
+ export function useStableReference<T extends Record<string, any>>(value: T) {
6
+ const ref = useRef(value)
7
+
8
+ const hasChanged = !deepEqual(ref.current, value)
9
+
10
+ if (hasChanged) {
11
+ ref.current = value
12
+ }
13
+
14
+ return ref.current
15
+ }
@@ -40,7 +40,7 @@ export function useUncontrolled<T>({
40
40
  const [uncontrolledValue, setUncontrolledValue] = useState(initialValue)
41
41
 
42
42
  // compute effective value
43
- let effectiveValue = shouldBeControlled ? value : uncontrolledValue
43
+ let effectiveValue: T | null = (shouldBeControlled ? value : uncontrolledValue) ?? null
44
44
 
45
45
  if (!shouldBeControlled && modeRef.current === 'controlled') {
46
46
  // We are transitioning from controlled to uncontrolled
package/package.json.bak DELETED
@@ -1,30 +0,0 @@
1
- {
2
- "name": "@codeleap/hooks",
3
- "version": "6.3.0",
4
- "main": "src/index.ts",
5
- "license": "UNLICENSED",
6
- "repository": {
7
- "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
8
- "type": "git",
9
- "directory": "packages/hooks"
10
- },
11
- "devDependencies": {
12
- "@codeleap/config": "workspace:*",
13
- "@codeleap/types": "workspace:*",
14
- "@codeleap/utils": "workspace:*",
15
- "@codeleap/logger": "workspace:*",
16
- "ts-node-dev": "1.1.8"
17
- },
18
- "scripts": {
19
- "build": "echo 'No build needed'"
20
- },
21
- "peerDependencies": {
22
- "@codeleap/types": "workspace:*",
23
- "@codeleap/utils": "workspace:*",
24
- "@codeleap/logger": "workspace:*",
25
- "axios": "^1.7.9",
26
- "typescript": "5.5.2",
27
- "react": "19.1.0",
28
- "@tanstack/react-query": "5.89.0"
29
- }
30
- }