reactives-hooks 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.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/dist/index.cjs +832 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +221 -0
- package/dist/index.d.ts +221 -0
- package/dist/index.mjs +792 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next/index.cjs +106 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +25 -0
- package/dist/next/index.d.ts +25 -0
- package/dist/next/index.mjs +101 -0
- package/dist/next/index.mjs.map +1 -0
- package/dist/utils/index.cjs +26 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.mjs +22 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +123 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 reactives contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# reactives-hooks
|
|
2
|
+
|
|
3
|
+
A collection of useful React hooks and utilities for React and Next.js.
|
|
4
|
+
|
|
5
|
+
- **TypeScript-first** — Full type safety with generics
|
|
6
|
+
- **Tree-shakeable** — Import only what you need
|
|
7
|
+
- **SSR-safe** — Works with Next.js SSR/SSG out of the box
|
|
8
|
+
- **Zero dependencies** — No bloat (except `cn` util which uses `clsx` + `tailwind-merge`)
|
|
9
|
+
- **React 18+** compatible (React 19 ready)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install reactives-hooks
|
|
15
|
+
# or
|
|
16
|
+
pnpm add reactives-hooks
|
|
17
|
+
# or
|
|
18
|
+
yarn add reactives-hooks
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { useToggle, useLocalStorage, useDebounceValue } from 'reactives-hooks'
|
|
25
|
+
import { useQueryParams } from 'reactives-hooks/next'
|
|
26
|
+
import { cn } from 'reactives-hooks/utils'
|
|
27
|
+
|
|
28
|
+
function App() {
|
|
29
|
+
const [isOpen, toggle] = useToggle(false)
|
|
30
|
+
const [theme, setTheme] = useLocalStorage('theme', 'light')
|
|
31
|
+
const debouncedSearch = useDebounceValue(search, 300)
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className={cn('container', isOpen && 'open')}>
|
|
35
|
+
<button onClick={toggle}>Toggle</button>
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Hooks
|
|
42
|
+
|
|
43
|
+
### State
|
|
44
|
+
- `useToggle` — Boolean toggle
|
|
45
|
+
- `useBoolean` — Explicit boolean controls (setTrue/setFalse/toggle)
|
|
46
|
+
- `useCounter` — Numeric counter with min/max
|
|
47
|
+
- `useMap` — Map state management
|
|
48
|
+
- `useSet` — Set state management
|
|
49
|
+
- `usePrevious` — Previous render value
|
|
50
|
+
- `useStateHistory` — Undo/redo state history
|
|
51
|
+
|
|
52
|
+
### Storage
|
|
53
|
+
- `useLocalStorage` — Synced localStorage with SSR safety
|
|
54
|
+
- `useSessionStorage` — Synced sessionStorage with SSR safety
|
|
55
|
+
|
|
56
|
+
### DOM
|
|
57
|
+
- `useEventListener` — Type-safe event listener
|
|
58
|
+
- `useClickOutside` — Outside click detection
|
|
59
|
+
- `useHover` — Hover state tracking
|
|
60
|
+
- `useIntersectionObserver` — Viewport intersection detection
|
|
61
|
+
- `useResizeObserver` — Element resize detection
|
|
62
|
+
- `useMutationObserver` — DOM mutation detection
|
|
63
|
+
|
|
64
|
+
### Sensor
|
|
65
|
+
- `useMediaQuery` — CSS media query matching
|
|
66
|
+
- `useWindowSize` — Window dimensions
|
|
67
|
+
- `useScroll` — Scroll position tracking
|
|
68
|
+
- `useMouse` — Mouse position tracking
|
|
69
|
+
- `useNetwork` — Network status and info
|
|
70
|
+
|
|
71
|
+
### Performance
|
|
72
|
+
- `useDebounceValue` — Debounced value
|
|
73
|
+
- `useDebounceCallback` — Debounced callback
|
|
74
|
+
- `useThrottleValue` — Throttled value
|
|
75
|
+
- `useThrottleCallback` — Throttled callback
|
|
76
|
+
|
|
77
|
+
### Lifecycle
|
|
78
|
+
- `useMount` — Run on mount
|
|
79
|
+
- `useUnmount` — Run on unmount
|
|
80
|
+
- `useUpdateEffect` — Skip first render effect
|
|
81
|
+
- `useIsMounted` — Mount status ref
|
|
82
|
+
- `useIsomorphicLayoutEffect` — SSR-safe useLayoutEffect
|
|
83
|
+
- `useDeepCompareEffect` — Deep comparison effect
|
|
84
|
+
|
|
85
|
+
### UI
|
|
86
|
+
- `useScrollLock` — Body scroll lock
|
|
87
|
+
- `useDarkMode` — Dark mode with system preference
|
|
88
|
+
- `useFullscreen` — Fullscreen API
|
|
89
|
+
- `useCopyToClipboard` — Clipboard copy
|
|
90
|
+
- `useHotkeys` — Keyboard shortcut binding
|
|
91
|
+
|
|
92
|
+
### Data
|
|
93
|
+
- `useAsync` — Async function wrapper
|
|
94
|
+
- `useFetch` — Fetch wrapper with abort
|
|
95
|
+
- `useInfiniteScroll` — Infinite scroll with IntersectionObserver
|
|
96
|
+
- `usePagination` — Pagination logic
|
|
97
|
+
|
|
98
|
+
### Next.js (`reactives-hooks/next`)
|
|
99
|
+
- `useQueryParams` — Typed URL query state
|
|
100
|
+
- `useRouteChange` — Route change detection
|
|
101
|
+
- `useSafeAction` — Server Action wrapper
|
|
102
|
+
- `useIsServer` — SSR/CSR detection
|
|
103
|
+
|
|
104
|
+
### Utils (`reactives-hooks/utils`)
|
|
105
|
+
- `cn` — Class name merge (clsx + tailwind-merge)
|
|
106
|
+
- `formatDate` — Date formatting (Intl.DateTimeFormat)
|
|
107
|
+
- `sleep` — Promise-based delay
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|