react-simplikit 0.0.52 → 0.1.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 (103) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +36 -26
  3. package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +1 -0
  4. package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +1 -0
  5. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +1 -0
  6. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +1 -0
  7. package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +1 -0
  8. package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +1 -0
  9. package/dist/hooks/useInputState/useInputState.cjs +9 -3
  10. package/dist/hooks/useInputState/useInputState.d.cts +11 -4
  11. package/dist/hooks/useInputState/useInputState.d.mts +11 -4
  12. package/dist/hooks/useInputState/useInputState.mjs +9 -3
  13. package/dist/hooks/useLoading/useLoading.cjs +3 -5
  14. package/dist/hooks/useLoading/useLoading.d.cts +2 -5
  15. package/dist/hooks/useLoading/useLoading.d.mts +2 -5
  16. package/dist/hooks/useLoading/useLoading.mjs +3 -5
  17. package/dist/hooks/usePreservedReference/usePreservedReference.cjs +1 -0
  18. package/dist/hooks/usePreservedReference/usePreservedReference.mjs +1 -0
  19. package/dist/hooks/usePrevious/usePrevious.cjs +1 -0
  20. package/dist/hooks/usePrevious/usePrevious.mjs +1 -0
  21. package/dist/hooks/useRefEffect/useRefEffect.cjs +1 -0
  22. package/dist/hooks/useRefEffect/useRefEffect.mjs +1 -0
  23. package/dist/hooks/useStorageState/useStorageState.cjs +1 -0
  24. package/dist/hooks/useStorageState/useStorageState.mjs +1 -0
  25. package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +9 -1
  26. package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +9 -1
  27. package/dist/index.cjs +34 -0
  28. package/dist/index.d.cts +19 -1
  29. package/dist/index.d.mts +19 -1
  30. package/dist/index.mjs +18 -1
  31. package/dist/mobile/hooks/useAvoidKeyboard/index.d.cts +3 -0
  32. package/dist/mobile/hooks/useAvoidKeyboard/index.d.mts +3 -0
  33. package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.cjs +75 -0
  34. package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.cts +89 -0
  35. package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.d.mts +89 -0
  36. package/dist/mobile/hooks/useAvoidKeyboard/useAvoidKeyboard.mjs +75 -0
  37. package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.cjs +47 -0
  38. package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.cts +37 -0
  39. package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.d.mts +37 -0
  40. package/dist/mobile/hooks/useBodyScrollLock/useBodyScrollLock.mjs +47 -0
  41. package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.cjs +41 -0
  42. package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.cts +41 -0
  43. package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.d.mts +41 -0
  44. package/dist/mobile/hooks/useKeyboardHeight/useKeyboardHeight.mjs +41 -0
  45. package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.cjs +88 -0
  46. package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.cts +77 -0
  47. package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.d.mts +77 -0
  48. package/dist/mobile/hooks/useNetworkStatus/useNetworkStatus.mjs +88 -0
  49. package/dist/mobile/hooks/usePageVisibility/usePageVisibility.cjs +73 -0
  50. package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.cts +62 -0
  51. package/dist/mobile/hooks/usePageVisibility/usePageVisibility.d.mts +62 -0
  52. package/dist/mobile/hooks/usePageVisibility/usePageVisibility.mjs +73 -0
  53. package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.cjs +74 -0
  54. package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.cts +55 -0
  55. package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.d.mts +55 -0
  56. package/dist/mobile/hooks/useSafeAreaInset/useSafeAreaInset.mjs +74 -0
  57. package/dist/mobile/hooks/useScrollDirection/useScrollDirection.cjs +79 -0
  58. package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.cts +40 -0
  59. package/dist/mobile/hooks/useScrollDirection/useScrollDirection.d.mts +40 -0
  60. package/dist/mobile/hooks/useScrollDirection/useScrollDirection.mjs +79 -0
  61. package/dist/mobile/hooks/useVisualViewport/useVisualViewport.cjs +77 -0
  62. package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.cts +89 -0
  63. package/dist/mobile/hooks/useVisualViewport/useVisualViewport.d.mts +89 -0
  64. package/dist/mobile/hooks/useVisualViewport/useVisualViewport.mjs +77 -0
  65. package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.cjs +55 -0
  66. package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.cts +22 -0
  67. package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.d.mts +22 -0
  68. package/dist/mobile/utils/disableBodyScrollLock/disableBodyScrollLock.mjs +55 -0
  69. package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.cjs +49 -0
  70. package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.cts +23 -0
  71. package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.d.mts +23 -0
  72. package/dist/mobile/utils/enableBodyScrollLock/enableBodyScrollLock.mjs +49 -0
  73. package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.cjs +35 -0
  74. package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.cts +28 -0
  75. package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.d.mts +28 -0
  76. package/dist/mobile/utils/getKeyboardHeight/getKeyboardHeight.mjs +35 -0
  77. package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.cjs +58 -0
  78. package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.cts +44 -0
  79. package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.d.mts +44 -0
  80. package/dist/mobile/utils/getSafeAreaInset/getSafeAreaInset.mjs +58 -0
  81. package/dist/mobile/utils/isAndroid/isAndroid.cjs +32 -0
  82. package/dist/mobile/utils/isAndroid/isAndroid.d.cts +27 -0
  83. package/dist/mobile/utils/isAndroid/isAndroid.d.mts +27 -0
  84. package/dist/mobile/utils/isAndroid/isAndroid.mjs +32 -0
  85. package/dist/mobile/utils/isIOS/isIOS.cjs +37 -0
  86. package/dist/mobile/utils/isIOS/isIOS.d.cts +30 -0
  87. package/dist/mobile/utils/isIOS/isIOS.d.mts +30 -0
  88. package/dist/mobile/utils/isIOS/isIOS.mjs +37 -0
  89. package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.cjs +28 -0
  90. package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.cts +25 -0
  91. package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.d.mts +25 -0
  92. package/dist/mobile/utils/isKeyboardVisible/isKeyboardVisible.mjs +28 -0
  93. package/dist/mobile/utils/isServer/isServer.cjs +24 -0
  94. package/dist/mobile/utils/isServer/isServer.d.cts +22 -0
  95. package/dist/mobile/utils/isServer/isServer.d.mts +22 -0
  96. package/dist/mobile/utils/isServer/isServer.mjs +24 -0
  97. package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.cjs +71 -0
  98. package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.cts +64 -0
  99. package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.d.mts +64 -0
  100. package/dist/mobile/utils/subscribeKeyboardHeight/subscribeKeyboardHeight.mjs +71 -0
  101. package/dist/utils/buildContext/buildContext.cjs +1 -0
  102. package/dist/utils/buildContext/buildContext.mjs +1 -0
  103. package/package.json +22 -8
package/CHANGELOG.md ADDED
@@ -0,0 +1,106 @@
1
+ # react-simplikit
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#437](https://github.com/toss/react-simplikit/pull/437) [`fe2226d`](https://github.com/toss/react-simplikit/commit/fe2226d5fbfcd305ab888cef83450f7f0e1caa77) Thanks [@mnxmnz](https://github.com/mnxmnz)! - Absorb `@react-simplikit/mobile` into the root export of `react-simplikit`. Update imports from `@react-simplikit/mobile` to `react-simplikit`; the exported APIs are unchanged. The `@react-simplikit/mobile` npm package will be deprecated with a pointer to `react-simplikit` after this release.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#423](https://github.com/toss/react-simplikit/pull/423) [`36e3e4c`](https://github.com/toss/react-simplikit/commit/36e3e4ccbd9c7a45bda18f33dcb514c97f387cbb) Thanks [@Antoliny0919](https://github.com/Antoliny0919)! - The returned handler was typed as `ChangeEventHandler<HTMLInputElement>`, so passing it to a `<textarea>` raised a type error even though the runtime behavior was identical. The handler is now typed as `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>`, so it can be attached to both `<input>` and `<textarea>` elements.
12
+
13
+ - [#424](https://github.com/toss/react-simplikit/pull/424) [`1ac0166`](https://github.com/toss/react-simplikit/commit/1ac0166d8f41c1159d004bd9c8192f2e59f6efc8) Thanks [@hyesungoh](https://github.com/hyesungoh)! - fix(core): opt the remaining React Compiler-incompatible hooks out with `'use no memo'`
14
+
15
+ ## 0.0.53
16
+
17
+ ### Patch Changes
18
+
19
+ - [#379](https://github.com/toss/react-simplikit/pull/379) [`e2030a2`](https://github.com/toss/react-simplikit/commit/e2030a2deac81fb247b9f601fab19d87a067cc9c) Thanks [@lumirlumir](https://github.com/lumirlumir)! - fix(usePrevious): opt out `usePrevious` hook from React Compiler
20
+
21
+ - [#404](https://github.com/toss/react-simplikit/pull/404) [`cac80cb`](https://github.com/toss/react-simplikit/commit/cac80cb41897b834bb3661336faa84197c558c1e) Thanks [@bbjbc](https://github.com/bbjbc)! - fix(useThrottledCallback): invoke the callback when the first value is `false`
22
+
23
+ The hook skips redundant invocations by comparing the incoming value against the last one it forwarded, but that comparison was seeded with `false`. Because the hook takes no initial value from the caller, a first call of `false` looked redundant and was dropped — so consumers whose state starts as `true` lost the transition back to `false`. The comparison now starts from a sentinel, so the first call is always forwarded regardless of its value.
24
+
25
+ ## 0.0.52
26
+
27
+ ### Patch Changes
28
+
29
+ - [#401](https://github.com/toss/react-simplikit/pull/401) [`9b93d29`](https://github.com/toss/react-simplikit/commit/9b93d299e9b105d060f2700b27ffb63001b88de3) Thanks [@hyesungoh](https://github.com/hyesungoh)! - Switched the build output from a single bundled file per package to per-module files, so bundlers can tree-shake unused exports at file granularity instead of relying on dead-code elimination inside one large bundle.
30
+
31
+ The public API and runtime behavior are unchanged. For an app importing a single hook, this cuts the amount of code a bundler has to include: `react-simplikit`'s `useToggle` drops from 5363 B to 102 B minified, and `@react-simplikit/mobile`'s `useNetworkStatus` drops from 981 B to 570 B minified.
32
+
33
+ The only user-visible change is packaging: output files are now `.mjs`/`.cjs` with `.d.mts`/`.d.cts` type declarations instead of a flat bundle, and for `react-simplikit` the `esm/` directory has been removed (`@react-simplikit/mobile` never had one — it always emitted to `dist/`). This does not affect the published `exports` map, so `import`/`require` usage is unaffected — only projects that deep-imported internal build paths (which were never part of the public `exports`) would be impacted.
34
+
35
+ ## 0.0.51
36
+
37
+ ### Patch Changes
38
+
39
+ - [#351](https://github.com/toss/react-simplikit/pull/351) [`da1f51c`](https://github.com/toss/react-simplikit/commit/da1f51cc9b860dde91dcfd120605eb6a93de3b55) Thanks [@eunwoo-levi](https://github.com/eunwoo-levi)! - fix(core/hooks): call cleanup when unmount occurs before async effect resolves
40
+
41
+ - [#352](https://github.com/toss/react-simplikit/pull/352) [`fa3daa5`](https://github.com/toss/react-simplikit/commit/fa3daa52d18644ac90a35fc8a79501eae7bb0269) Thanks [@eunwoo-levi](https://github.com/eunwoo-levi)! - fix(core/hooks): prevent immediate callback from re-firing when enabled is toggled
42
+
43
+ ## 0.0.50
44
+
45
+ ### Patch Changes
46
+
47
+ - [#362](https://github.com/toss/react-simplikit/pull/362) [`fc9b1dc`](https://github.com/toss/react-simplikit/commit/fc9b1dcc2be7902ffe487c5868180317b9f07730) Thanks [@guesung](https://github.com/guesung)! - refactor(core): narrow types in `debounce` utility to reduce `any` usage
48
+
49
+ - [#259](https://github.com/toss/react-simplikit/pull/259) [`1d9ec79`](https://github.com/toss/react-simplikit/commit/1d9ec7984899d1d8dcda16d15efa66f458c347fa) Thanks [@wo-o29](https://github.com/wo-o29)! - refactor(useCounter): extract validateValue as pure function and remove unnecessary useCallback
50
+
51
+ - [#272](https://github.com/toss/react-simplikit/pull/272) [`75ab148`](https://github.com/toss/react-simplikit/commit/75ab1484a1af68a2f27fa31da8f6094f0c63d37f) Thanks [@wo-o29](https://github.com/wo-o29)! - refactor(usePrevious): remove unnecessary `undefined` from compare argument and return type
52
+
53
+ ## 0.0.49
54
+
55
+ ### Patch Changes
56
+
57
+ - [#339](https://github.com/toss/react-simplikit/pull/339) [`e5f6cac`](https://github.com/toss/react-simplikit/commit/e5f6cacd0bc93c03f361d0c825424937bc141809) Thanks [@sukvvon](https://github.com/sukvvon)! - feat(core/hooks): add 'useSet' hook
58
+
59
+ - [#219](https://github.com/toss/react-simplikit/pull/219) [`2a901bb`](https://github.com/toss/react-simplikit/commit/2a901bb903f4663571c7649769d3e29c9e844332) Thanks [@sukvvon](https://github.com/sukvvon)! - feat(core/hooks): add 'useIsClient' hook
60
+
61
+ - [#273](https://github.com/toss/react-simplikit/pull/273) [`ffc61bb`](https://github.com/toss/react-simplikit/commit/ffc61bb998fdaf129fff12e5e7515007ca5eeb51) Thanks [@wo-o29](https://github.com/wo-o29)! - docs: Add generic type support to useRefEffect interface
62
+
63
+ - [#278](https://github.com/toss/react-simplikit/pull/278) [`278b117`](https://github.com/toss/react-simplikit/commit/278b117152f8f01c54a66fc91c7c4c03fc74f7d9) Thanks [@wo-o29](https://github.com/wo-o29)! - fix: Replace array index keys with child keys in Separated
64
+
65
+ - [#347](https://github.com/toss/react-simplikit/pull/347) [`9a358e2`](https://github.com/toss/react-simplikit/commit/9a358e28e5407ab93c41dec486d932bbc9c42a64) Thanks [@eunwoo-levi](https://github.com/eunwoo-levi)! - use named functions in useEffect callbacks for better stack traces
66
+
67
+ - [#345](https://github.com/toss/react-simplikit/pull/345) [`35d13f8`](https://github.com/toss/react-simplikit/commit/35d13f8fb0aa12dd2c1e5aa15ae18f823ec323fd) Thanks [@eunwoo-levi](https://github.com/eunwoo-levi)! - fix useInterval to use globalThis instead of window for platform independence
68
+
69
+ - [`68e7ac8`](https://github.com/toss/react-simplikit/commit/68e7ac86650026709f2be7498c830dfe5cfdc2e1) Thanks [@sukvvon](https://github.com/sukvvon)! - feat(core/hooks): add 'useList' hook
70
+
71
+ - [`4b0c59e`](https://github.com/toss/react-simplikit/commit/4b0c59edb599406535a479c1f099a272c399ee99) Thanks [@sukvvon](https://github.com/sukvvon)! - feat(core/hooks): add 'useThrottledCallback' hook
72
+
73
+ - [#333](https://github.com/toss/react-simplikit/pull/333) [`4254542`](https://github.com/toss/react-simplikit/commit/4254542e481374c7f0e4de6dbacdfd10f076e529) Thanks [@dlsxjzld](https://github.com/dlsxjzld)! - remove window prefix from setTimeout and clearTimeout for platform-independent
74
+
75
+ ## 0.0.48
76
+
77
+ ### Patch Changes
78
+
79
+ - [#318](https://github.com/toss/react-simplikit/pull/318) [`466e3ce`](https://github.com/toss/react-simplikit/commit/466e3ceab51a499abb141bc1fe138d9109cc0df5) Thanks [@kimyouknow](https://github.com/kimyouknow)! - Fix broken package exports by moving main/types/module/exports from publishConfig to top-level package.json fields
80
+
81
+ npm does not support publishConfig field overrides for manifest fields like main, types, and exports. The previous versions (react-simplikit@0.0.47, @react-simplikit/mobile@0.0.1) were published with incorrect entry points because publishConfig overrides were not applied during `npm publish`.
82
+
83
+ ## 0.0.47
84
+
85
+ ### Patch Changes
86
+
87
+ - [#316](https://github.com/toss/react-simplikit/pull/316) [`5b2eeba`](https://github.com/toss/react-simplikit/commit/5b2eeba659206cf9577dd57796a4770d07a33f62) Thanks [@kimyouknow](https://github.com/kimyouknow)! - Deprecate hooks that depend on browser-specific APIs
88
+
89
+ The following hooks are now marked as deprecated:
90
+
91
+ - `useDoubleClick`
92
+ - `useGeolocation`
93
+ - `useImpressionRef`
94
+ - `useIntersectionObserver`
95
+ - `useLongPress`
96
+ - `useOutsideClickEffect`
97
+ - `useStorageState`
98
+ - `useVisibilityEvent`
99
+
100
+ These hooks will be removed in a future major version as react-simplikit is now focused on platform-independent, pure state/logic hooks.
101
+
102
+ ## 0.0.46
103
+
104
+ ### Patch Changes
105
+
106
+ - [#292](https://github.com/toss/react-simplikit/pull/292) [`afaafd3`](https://github.com/toss/react-simplikit/commit/afaafd397a8c23caf26d8eb3167a31a06a864b2f) Thanks [@kimyouknow](https://github.com/kimyouknow)! - verify changeset automation workflow
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toss/react-simplikit/blob/main/LICENSE)
5
5
  [![codecov](https://codecov.io/gh/toss/react-simplikit/graph/badge.svg?token=RHVOZ3J3TU)](https://codecov.io/gh/toss/react-simplikit)
6
6
 
7
- English | [한국어](./README-ko_kr.md)
7
+ English | [한국어](./README-ko_kr.md) | [日本語](./README-ja_jp.md)
8
8
 
9
9
  A lightweight, zero-dependency React utilities library providing hooks, components, and utilities.
10
10
 
@@ -27,7 +27,7 @@ We are repositioning react-simplikit to focus exclusively on **platform-independ
27
27
  Hooks that don't depend on specific platform APIs will continue to be actively maintained:
28
28
 
29
29
  - State management hooks like `useToggle`, `useBooleanState`, `useCounter`
30
- - Lifecycle hooks like `usePrevious`, `useMount`
30
+ - Lifecycle hooks like `usePrevious`
31
31
  - Utility hooks like `useDebounce`, `useThrottle`
32
32
  - **Backward compatibility (BC) is preserved** for these existing pure logic hooks
33
33
 
@@ -69,37 +69,46 @@ pnpm add react-simplikit
69
69
  ## Quick Start
70
70
 
71
71
  ```tsx
72
- import { useState, useEffect } from 'react';
72
+ import { useState } from 'react';
73
73
  import { useDebounce } from 'react-simplikit';
74
74
 
75
75
  function SearchInput() {
76
76
  const [query, setQuery] = useState('');
77
- const debouncedQuery = useDebounce(query, 300);
78
77
 
79
- useEffect(() => {
80
- if (debouncedQuery) {
81
- searchAPI(debouncedQuery);
82
- }
83
- }, [debouncedQuery]);
84
-
85
- return <input value={query} onChange={e => setQuery(e.target.value)} />;
78
+ const debouncedSearch = useDebounce((value: string) => {
79
+ // Actual API call
80
+ searchAPI(value);
81
+ }, 300);
82
+
83
+ return (
84
+ <input
85
+ value={query}
86
+ onChange={e => {
87
+ setQuery(e.target.value);
88
+ debouncedSearch(e.target.value);
89
+ }}
90
+ placeholder="Enter search term"
91
+ />
92
+ );
86
93
  }
87
94
  ```
88
95
 
96
+ The debounced function exposes `.cancel()`, and pending calls are cancelled automatically when the component unmounts.
97
+
89
98
  ## What's Included
90
99
 
91
100
  ### Hooks
92
101
 
93
- | Hook | Description |
94
- | ------------------------- | --------------------------------------------------- |
95
- | `useBooleanState` | Manage boolean state with handlers |
96
- | `useDebounce` | Debounce a value |
97
- | `useDebouncedCallback` | Debounce a callback function |
98
- | `useInterval` | Set up intervals declaratively |
99
- | `useIntersectionObserver` | Observe element visibility |
100
- | `usePreservedCallback` | Stable callback reference |
101
- | `usePreservedReference` | Stable object reference |
102
- | ... | [See all hooks](https://react-simplikit.slash.page) |
102
+ | Hook | Description |
103
+ | ------------------------- | ----------------------------------------------------- |
104
+ | `useBooleanState` | Manage boolean state with handlers |
105
+ | `useDebounce` | Debounce a callback function |
106
+ | `useDebouncedCallback` | Debounce an `onChange` callback via an options object |
107
+ | `useInterval` | Set up intervals declaratively |
108
+ | `useIntersectionObserver` | Observe element visibility |
109
+ | `usePreservedCallback` | Stable callback reference |
110
+ | `usePreservedReference` | Stable object reference |
111
+ | ... | [See all hooks](https://react-simplikit.slash.page) |
103
112
 
104
113
  ### Components
105
114
 
@@ -111,10 +120,11 @@ function SearchInput() {
111
120
 
112
121
  ### Utilities
113
122
 
114
- | Utility | Description |
115
- | -------- | ----------------- |
116
- | `assert` | Runtime assertion |
117
- | `noop` | Empty function |
123
+ | Utility | Description |
124
+ | -------------- | --------------------------------------------------- |
125
+ | `buildContext` | Define React Context with less boilerplate |
126
+ | `mergeProps` | Merge props, composing `className`, `style`, events |
127
+ | `mergeRefs` | Combine multiple refs into a single ref |
118
128
 
119
129
  ## Documentation
120
130
 
@@ -122,7 +132,7 @@ Visit [react-simplikit.slash.page](https://react-simplikit.slash.page) for full
122
132
 
123
133
  ## Related Packages
124
134
 
125
- - [@react-simplikit/mobile](https://www.npmjs.com/package/@react-simplikit/mobile) - Mobile web utilities
135
+ - [Mobile web utilities](https://react-simplikit.slash.page/mobile/intro.html) - included in `react-simplikit`
126
136
 
127
137
  ## Contributing
128
138
 
@@ -22,6 +22,7 @@ let react = require("react");
22
22
  * }, [dependencies]);
23
23
  */
24
24
  function useAsyncEffect(effect, deps) {
25
+ "use no memo";
25
26
  (0, react.useEffect)(() => {
26
27
  let cleanup;
27
28
  let isCleaned = false;
@@ -22,6 +22,7 @@ import { useEffect } from "react";
22
22
  * }, [dependencies]);
23
23
  */
24
24
  function useAsyncEffect(effect, deps) {
25
+ "use no memo";
25
26
  useEffect(() => {
26
27
  let cleanup;
27
28
  let isCleaned = false;
@@ -38,6 +38,7 @@ let react = require("react");
38
38
  * }
39
39
  */
40
40
  function useCallbackOncePerRender(callback, deps) {
41
+ "use no memo";
41
42
  const hasFired = (0, react.useRef)(false);
42
43
  (0, react.useEffect)(() => {
43
44
  hasFired.current = false;
@@ -38,6 +38,7 @@ import { useEffect, useRef } from "react";
38
38
  * }
39
39
  */
40
40
  function useCallbackOncePerRender(callback, deps) {
41
+ "use no memo";
41
42
  const hasFired = useRef(false);
42
43
  useEffect(() => {
43
44
  hasFired.current = false;
@@ -40,6 +40,7 @@ let react = require("react");
40
40
  *
41
41
  */
42
42
  function useConditionalEffect(effect, deps, condition) {
43
+ "use no memo";
43
44
  const prevDepsRef = (0, react.useRef)(void 0);
44
45
  const memoizedCondition = (0, react.useCallback)(condition, deps);
45
46
  if (deps.length === 0) console.warn("useConditionalEffect received an empty dependency array. This may indicate missing dependencies and could lead to unexpected behavior.");
@@ -40,6 +40,7 @@ import { useCallback, useEffect, useRef } from "react";
40
40
  *
41
41
  */
42
42
  function useConditionalEffect(effect, deps, condition) {
43
+ "use no memo";
43
44
  const prevDepsRef = useRef(void 0);
44
45
  const memoizedCondition = useCallback(condition, deps);
45
46
  if (deps.length === 0) console.warn("useConditionalEffect received an empty dependency array. This may indicate missing dependencies and could lead to unexpected behavior.");
@@ -4,19 +4,25 @@ let react = require("react");
4
4
  /**
5
5
  * @description
6
6
  * `useInputState` is a React hook that manages an input state with optional value transformation.
7
+ * The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
7
8
  *
8
9
  * @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
9
10
  * @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
10
11
  * Defaults to an identity function that returns the input unchanged.
11
12
  *
12
- * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
13
+ * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
13
14
  * - value `string` - The current state value;
14
- * - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
15
+ * - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
15
16
  *
16
17
  * @example
17
18
  * function Example() {
18
19
  * const [value, onChange] = useInputState('');
19
- * return <input type="text" value={value} onChange={onChange} />;
20
+ * return (
21
+ * <>
22
+ * <input type="text" value={value} onChange={onChange} />
23
+ * <textarea value={value} onChange={onChange} />
24
+ * </>
25
+ * );
20
26
  * }
21
27
  */
22
28
  function useInputState(initialValue = "", transformValue = echo) {
@@ -1,24 +1,31 @@
1
1
 
2
2
  import { ChangeEventHandler } from "react";
3
3
  //#region src/hooks/useInputState/useInputState.d.ts
4
+ type InputLikeElement = HTMLInputElement | HTMLTextAreaElement;
4
5
  /**
5
6
  * @description
6
7
  * `useInputState` is a React hook that manages an input state with optional value transformation.
8
+ * The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
7
9
  *
8
10
  * @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
9
11
  * @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
10
12
  * Defaults to an identity function that returns the input unchanged.
11
13
  *
12
- * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
14
+ * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
13
15
  * - value `string` - The current state value;
14
- * - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
16
+ * - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
15
17
  *
16
18
  * @example
17
19
  * function Example() {
18
20
  * const [value, onChange] = useInputState('');
19
- * return <input type="text" value={value} onChange={onChange} />;
21
+ * return (
22
+ * <>
23
+ * <input type="text" value={value} onChange={onChange} />
24
+ * <textarea value={value} onChange={onChange} />
25
+ * </>
26
+ * );
20
27
  * }
21
28
  */
22
- declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<HTMLInputElement>];
29
+ declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<InputLikeElement>];
23
30
  //#endregion
24
31
  export { useInputState };
@@ -1,24 +1,31 @@
1
1
 
2
2
  import { ChangeEventHandler } from "react";
3
3
  //#region src/hooks/useInputState/useInputState.d.ts
4
+ type InputLikeElement = HTMLInputElement | HTMLTextAreaElement;
4
5
  /**
5
6
  * @description
6
7
  * `useInputState` is a React hook that manages an input state with optional value transformation.
8
+ * The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
7
9
  *
8
10
  * @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
9
11
  * @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
10
12
  * Defaults to an identity function that returns the input unchanged.
11
13
  *
12
- * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
14
+ * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
13
15
  * - value `string` - The current state value;
14
- * - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
16
+ * - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
15
17
  *
16
18
  * @example
17
19
  * function Example() {
18
20
  * const [value, onChange] = useInputState('');
19
- * return <input type="text" value={value} onChange={onChange} />;
21
+ * return (
22
+ * <>
23
+ * <input type="text" value={value} onChange={onChange} />
24
+ * <textarea value={value} onChange={onChange} />
25
+ * </>
26
+ * );
20
27
  * }
21
28
  */
22
- declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<HTMLInputElement>];
29
+ declare function useInputState(initialValue?: string, transformValue?: (value: string) => string): readonly [string, ChangeEventHandler<InputLikeElement>];
23
30
  //#endregion
24
31
  export { useInputState };
@@ -4,19 +4,25 @@ import { useCallback, useState } from "react";
4
4
  /**
5
5
  * @description
6
6
  * `useInputState` is a React hook that manages an input state with optional value transformation.
7
+ * The returned `onChange` handler works with both `<input>` and `<textarea>` elements.
7
8
  *
8
9
  * @param {string} [initialValue=""] - The initial value of the input. Defaults to an empty string (`""`).
9
10
  * @param {(value: string) => string} [transformValue=(v: string) => v] - A function to transform the input value.
10
11
  * Defaults to an identity function that returns the input unchanged.
11
12
  *
12
- * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement>]} A tuple containing:
13
+ * @returns {[value: string, onChange: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>]} A tuple containing:
13
14
  * - value `string` - The current state value;
14
- * - onChange `ChangeEventHandler<HTMLInputElement>` - A function to update the state;
15
+ * - onChange `ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>` - A function to update the state;
15
16
  *
16
17
  * @example
17
18
  * function Example() {
18
19
  * const [value, onChange] = useInputState('');
19
- * return <input type="text" value={value} onChange={onChange} />;
20
+ * return (
21
+ * <>
22
+ * <input type="text" value={value} onChange={onChange} />
23
+ * <textarea value={value} onChange={onChange} />
24
+ * </>
25
+ * );
20
26
  * }
21
27
  */
22
28
  function useInputState(initialValue = "", transformValue = echo) {
@@ -7,12 +7,9 @@ let react = require("react");
7
7
  * It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
8
8
  *
9
9
  * @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
10
- * - loading `boolean` - Represents the current loading state.
11
- * : The initial value is `false`.
12
- * : It is set to `true` when an asynchronous task is in progress;
10
+ * - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
13
11
  *
14
- * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
15
- * : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
12
+ * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
16
13
  *
17
14
  * @example
18
15
  * function ConfirmButton() {
@@ -48,6 +45,7 @@ function useLoading() {
48
45
  return (0, react.useMemo)(() => [loading, startTransition], [loading, startTransition]);
49
46
  }
50
47
  function useIsMountedRef() {
48
+ "use no memo";
51
49
  const ref = (0, react.useRef)({ isMounted: true }).current;
52
50
  (0, react.useEffect)(function trackMountedState() {
53
51
  ref.isMounted = true;
@@ -6,12 +6,9 @@
6
6
  * It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
7
7
  *
8
8
  * @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
9
- * - loading `boolean` - Represents the current loading state.
10
- * : The initial value is `false`.
11
- * : It is set to `true` when an asynchronous task is in progress;
9
+ * - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
12
10
  *
13
- * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
14
- * : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
11
+ * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
15
12
  *
16
13
  * @example
17
14
  * function ConfirmButton() {
@@ -6,12 +6,9 @@
6
6
  * It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
7
7
  *
8
8
  * @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
9
- * - loading `boolean` - Represents the current loading state.
10
- * : The initial value is `false`.
11
- * : It is set to `true` when an asynchronous task is in progress;
9
+ * - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
12
10
  *
13
- * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
14
- * : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
11
+ * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
15
12
  *
16
13
  * @example
17
14
  * function ConfirmButton() {
@@ -7,12 +7,9 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
7
7
  * It provides a state to track whether an asynchronous operation is in progress and a function to handle the loading state automatically.
8
8
  *
9
9
  * @returns {[loading: boolean, startLoading: <T>(promise: Promise<T>) => Promise<T>]} A tuple containing:
10
- * - loading `boolean` - Represents the current loading state.
11
- * : The initial value is `false`.
12
- * : It is set to `true` when an asynchronous task is in progress;
10
+ * - loading `boolean` - Represents the current loading state. The initial value is `false`. It is set to `true` when an asynchronous task is in progress;
13
11
  *
14
- * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state.
15
- * : This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
12
+ * - startLoading `<T>(promise: Promise<T>) => Promise<T>` - A function that executes asynchronous tasks while managing the loading state. This function takes a `Promise` as an argument and automatically resets the `isLoading` state to `false` when the `Promise` completes;
16
13
  *
17
14
  * @example
18
15
  * function ConfirmButton() {
@@ -48,6 +45,7 @@ function useLoading() {
48
45
  return useMemo(() => [loading, startTransition], [loading, startTransition]);
49
46
  }
50
47
  function useIsMountedRef() {
48
+ "use no memo";
51
49
  const ref = useRef({ isMounted: true }).current;
52
50
  useEffect(function trackMountedState() {
53
51
  ref.isMounted = true;
@@ -42,6 +42,7 @@ let react = require("react");
42
42
  * }
43
43
  */
44
44
  function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
45
+ "use no memo";
45
46
  const ref = (0, react.useRef)(value);
46
47
  return (0, react.useMemo)(() => {
47
48
  if (!areValuesEqual(ref.current, value)) ref.current = value;
@@ -42,6 +42,7 @@ import { useMemo, useRef } from "react";
42
42
  * }
43
43
  */
44
44
  function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
45
+ "use no memo";
45
46
  const ref = useRef(value);
46
47
  return useMemo(() => {
47
48
  if (!areValuesEqual(ref.current, value)) ref.current = value;
@@ -21,6 +21,7 @@ const strictEquals = (prev, next) => prev === next;
21
21
  * const previousCount = usePrevious(count);
22
22
  */
23
23
  function usePrevious(state, compare = strictEquals) {
24
+ "use no memo";
24
25
  const prevRef = (0, react.useRef)(state);
25
26
  const currentRef = (0, react.useRef)(state);
26
27
  const isFirstRender = (0, react.useRef)(true);
@@ -21,6 +21,7 @@ const strictEquals = (prev, next) => prev === next;
21
21
  * const previousCount = usePrevious(count);
22
22
  */
23
23
  function usePrevious(state, compare = strictEquals) {
24
+ "use no memo";
24
25
  const prevRef = useRef(state);
25
26
  const currentRef = useRef(state);
26
27
  const isFirstRender = useRef(true);
@@ -28,6 +28,7 @@ let react = require("react");
28
28
  * }
29
29
  */
30
30
  function useRefEffect(callback, deps) {
31
+ "use no memo";
31
32
  const preservedCallback = require_usePreservedCallback.usePreservedCallback(callback);
32
33
  const cleanupCallbackRef = (0, react.useRef)(() => {});
33
34
  return (0, react.useCallback)((element) => {
@@ -28,6 +28,7 @@ import { useCallback, useRef } from "react";
28
28
  * }
29
29
  */
30
30
  function useRefEffect(callback, deps) {
31
+ "use no memo";
31
32
  const preservedCallback = usePreservedCallback(callback);
32
33
  const cleanupCallbackRef = useRef(() => {});
33
34
  return useCallback((element) => {
@@ -20,6 +20,7 @@ const ensureSerializable = (value) => {
20
20
  return value;
21
21
  };
22
22
  function useStorageState(key, { storage = require_storage.safeLocalStorage, defaultValue, ...options } = {}) {
23
+ "use no memo";
23
24
  const serializedDefaultValue = defaultValue;
24
25
  const cache = (0, react.useRef)({
25
26
  data: null,
@@ -20,6 +20,7 @@ const ensureSerializable = (value) => {
20
20
  return value;
21
21
  };
22
22
  function useStorageState(key, { storage = safeLocalStorage, defaultValue, ...options } = {}) {
23
+ "use no memo";
23
24
  const serializedDefaultValue = defaultValue;
24
25
  const cache = useRef({
25
26
  data: null,
@@ -5,6 +5,14 @@ const require_throttle = require("../useThrottle/throttle.cjs");
5
5
  let react = require("react");
6
6
  //#region src/hooks/useThrottledCallback/useThrottledCallback.ts
7
7
  /**
8
+ * Marks that no value has been forwarded to `onChange` yet.
9
+ *
10
+ * The hook skips redundant invocations by comparing against the last forwarded value, but it
11
+ * receives no initial value from the caller. Seeding that comparison with `false` would treat the
12
+ * first `false` as redundant and swallow it, so an unreachable sentinel is used instead.
13
+ */
14
+ const NOT_INVOKED = Symbol("NOT_INVOKED");
15
+ /**
8
16
  * @description
9
17
  * `useThrottledCallback` is a React hook that returns a throttled version of the provided callback function.
10
18
  * The throttled callback will only be invoked at most once per specified interval.
@@ -28,7 +36,7 @@ let react = require("react");
28
36
  function useThrottledCallback({ onChange, timeThreshold, edges = ["leading", "trailing"] }) {
29
37
  const handleChange = require_usePreservedCallback.usePreservedCallback(onChange);
30
38
  const ref = (0, react.useRef)({
31
- value: false,
39
+ value: NOT_INVOKED,
32
40
  clearPreviousThrottle: () => {}
33
41
  });
34
42
  (0, react.useEffect)(function cleanupThrottleOnUnmount() {
@@ -5,6 +5,14 @@ import { throttle } from "../useThrottle/throttle.mjs";
5
5
  import { useCallback, useEffect, useRef } from "react";
6
6
  //#region src/hooks/useThrottledCallback/useThrottledCallback.ts
7
7
  /**
8
+ * Marks that no value has been forwarded to `onChange` yet.
9
+ *
10
+ * The hook skips redundant invocations by comparing against the last forwarded value, but it
11
+ * receives no initial value from the caller. Seeding that comparison with `false` would treat the
12
+ * first `false` as redundant and swallow it, so an unreachable sentinel is used instead.
13
+ */
14
+ const NOT_INVOKED = Symbol("NOT_INVOKED");
15
+ /**
8
16
  * @description
9
17
  * `useThrottledCallback` is a React hook that returns a throttled version of the provided callback function.
10
18
  * The throttled callback will only be invoked at most once per specified interval.
@@ -28,7 +36,7 @@ import { useCallback, useEffect, useRef } from "react";
28
36
  function useThrottledCallback({ onChange, timeThreshold, edges = ["leading", "trailing"] }) {
29
37
  const handleChange = usePreservedCallback(onChange);
30
38
  const ref = useRef({
31
- value: false,
39
+ value: NOT_INVOKED,
32
40
  clearPreviousThrottle: () => {}
33
41
  });
34
42
  useEffect(function cleanupThrottleOnUnmount() {