@foundrykit/hooks 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @foundrykit/hooks
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updating versions to ensure they are inline
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @foundrykit/hooks
2
2
 
3
- A collection of custom React hooks for common UI patterns and functionality. Provides reusable logic for state management, user interactions, and component behavior.
3
+ A collection of custom React hooks for common UI patterns and functionality.
4
+ Provides reusable logic for state management, user interactions, and component
5
+ behavior.
4
6
 
5
7
  ## Features
6
8
 
@@ -19,22 +21,26 @@ pnpm add @foundrykit/hooks
19
21
  ## Available Hooks
20
22
 
21
23
  ### State Management
24
+
22
25
  - **useLocalStorage** - Persist state in localStorage
23
26
  - **useDebouncedValue** - Debounce values for performance
24
27
  - **useMediaQuery** - React to media query changes
25
28
  - **useClickOutside** - Detect clicks outside elements
26
29
 
27
30
  ### Form Hooks
31
+
28
32
  - **useForm** - Form state management
29
33
  - **useField** - Individual field management
30
34
  - **useValidation** - Form validation logic
31
35
 
32
36
  ### UI Hooks
37
+
33
38
  - **useDialog** - Dialog/modal state management
34
39
  - **usePopover** - Popover positioning and state
35
40
  - **useTooltip** - Tooltip positioning and visibility
36
41
 
37
42
  ### Utility Hooks
43
+
38
44
  - **usePrevious** - Access previous value
39
45
  - **useInterval** - Set up intervals with cleanup
40
46
  - **useTimeout** - Set up timeouts with cleanup
@@ -48,25 +54,25 @@ pnpm add @foundrykit/hooks
48
54
  Persist state in localStorage with automatic serialization:
49
55
 
50
56
  ```tsx
51
- import { useLocalStorage } from '@foundrykit/hooks'
57
+ import { useLocalStorage } from '@foundrykit/hooks';
52
58
 
53
59
  function UserPreferences() {
54
- const [theme, setTheme] = useLocalStorage('theme', 'light')
55
- const [language, setLanguage] = useLocalStorage('language', 'en')
60
+ const [theme, setTheme] = useLocalStorage('theme', 'light');
61
+ const [language, setLanguage] = useLocalStorage('language', 'en');
56
62
 
57
63
  return (
58
64
  <div>
59
- <select value={theme} onChange={(e) => setTheme(e.target.value)}>
60
- <option value="light">Light</option>
61
- <option value="dark">Dark</option>
65
+ <select value={theme} onChange={e => setTheme(e.target.value)}>
66
+ <option value='light'>Light</option>
67
+ <option value='dark'>Dark</option>
62
68
  </select>
63
-
64
- <select value={language} onChange={(e) => setLanguage(e.target.value)}>
65
- <option value="en">English</option>
66
- <option value="es">Spanish</option>
69
+
70
+ <select value={language} onChange={e => setLanguage(e.target.value)}>
71
+ <option value='en'>English</option>
72
+ <option value='es'>Spanish</option>
67
73
  </select>
68
74
  </div>
69
- )
75
+ );
70
76
  }
71
77
  ```
72
78
 
@@ -75,26 +81,26 @@ function UserPreferences() {
75
81
  Debounce values to improve performance:
76
82
 
77
83
  ```tsx
78
- import { useDebouncedValue } from '@foundrykit/hooks'
84
+ import { useDebouncedValue } from '@foundrykit/hooks';
79
85
 
80
86
  function SearchComponent() {
81
- const [query, setQuery] = useState('')
82
- const debouncedQuery = useDebouncedValue(query, 300)
87
+ const [query, setQuery] = useState('');
88
+ const debouncedQuery = useDebouncedValue(query, 300);
83
89
 
84
90
  // This effect only runs when debouncedQuery changes
85
91
  useEffect(() => {
86
92
  if (debouncedQuery) {
87
- searchAPI(debouncedQuery)
93
+ searchAPI(debouncedQuery);
88
94
  }
89
- }, [debouncedQuery])
95
+ }, [debouncedQuery]);
90
96
 
91
97
  return (
92
98
  <input
93
99
  value={query}
94
- onChange={(e) => setQuery(e.target.value)}
95
- placeholder="Search..."
100
+ onChange={e => setQuery(e.target.value)}
101
+ placeholder='Search...'
96
102
  />
97
- )
103
+ );
98
104
  }
99
105
  ```
100
106
 
@@ -103,12 +109,12 @@ function SearchComponent() {
103
109
  React to media query changes:
104
110
 
105
111
  ```tsx
106
- import { useMediaQuery } from '@foundrykit/hooks'
112
+ import { useMediaQuery } from '@foundrykit/hooks';
107
113
 
108
114
  function ResponsiveComponent() {
109
- const isMobile = useMediaQuery('(max-width: 768px)')
110
- const isTablet = useMediaQuery('(min-width: 769px) and (max-width: 1024px)')
111
- const isDesktop = useMediaQuery('(min-width: 1025px)')
115
+ const isMobile = useMediaQuery('(max-width: 768px)');
116
+ const isTablet = useMediaQuery('(min-width: 769px) and (max-width: 1024px)');
117
+ const isDesktop = useMediaQuery('(min-width: 1025px)');
112
118
 
113
119
  return (
114
120
  <div>
@@ -116,7 +122,7 @@ function ResponsiveComponent() {
116
122
  {isTablet && <TabletLayout />}
117
123
  {isDesktop && <DesktopLayout />}
118
124
  </div>
119
- )
125
+ );
120
126
  }
121
127
  ```
122
128
 
@@ -127,24 +133,24 @@ function ResponsiveComponent() {
127
133
  Detect clicks outside an element:
128
134
 
129
135
  ```tsx
130
- import { useClickOutside } from '@foundrykit/hooks'
136
+ import { useClickOutside } from '@foundrykit/hooks';
131
137
 
132
138
  function Dropdown({ isOpen, onClose, children }) {
133
- const ref = useRef(null)
134
-
139
+ const ref = useRef(null);
140
+
135
141
  useClickOutside(ref, () => {
136
142
  if (isOpen) {
137
- onClose()
143
+ onClose();
138
144
  }
139
- })
145
+ });
140
146
 
141
- if (!isOpen) return null
147
+ if (!isOpen) return null;
142
148
 
143
149
  return (
144
- <div ref={ref} className="dropdown">
150
+ <div ref={ref} className='dropdown'>
145
151
  {children}
146
152
  </div>
147
- )
153
+ );
148
154
  }
149
155
  ```
150
156
 
@@ -153,25 +159,25 @@ function Dropdown({ isOpen, onClose, children }) {
153
159
  Manage dialog/modal state:
154
160
 
155
161
  ```tsx
156
- import { useDialog } from '@foundrykit/hooks'
162
+ import { useDialog } from '@foundrykit/hooks';
157
163
 
158
164
  function ModalExample() {
159
- const { isOpen, open, close, toggle } = useDialog()
165
+ const { isOpen, open, close, toggle } = useDialog();
160
166
 
161
167
  return (
162
168
  <div>
163
169
  <button onClick={open}>Open Modal</button>
164
-
170
+
165
171
  {isOpen && (
166
- <div className="modal-overlay" onClick={close}>
167
- <div className="modal-content" onClick={(e) => e.stopPropagation()}>
172
+ <div className='modal-overlay' onClick={close}>
173
+ <div className='modal-content' onClick={e => e.stopPropagation()}>
168
174
  <h2>Modal Content</h2>
169
175
  <button onClick={close}>Close</button>
170
176
  </div>
171
177
  </div>
172
178
  )}
173
179
  </div>
174
- )
180
+ );
175
181
  }
176
182
  ```
177
183
 
@@ -182,61 +188,69 @@ function ModalExample() {
182
188
  Complete form state management:
183
189
 
184
190
  ```tsx
185
- import { useForm } from '@foundrykit/hooks'
191
+ import { useForm } from '@foundrykit/hooks';
186
192
 
187
193
  function ContactForm() {
188
- const { values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting } = useForm({
194
+ const {
195
+ values,
196
+ errors,
197
+ touched,
198
+ handleChange,
199
+ handleBlur,
200
+ handleSubmit,
201
+ isSubmitting,
202
+ } = useForm({
189
203
  initialValues: {
190
204
  name: '',
191
205
  email: '',
192
- message: ''
206
+ message: '',
193
207
  },
194
- validate: (values) => {
195
- const errors = {}
196
- if (!values.name) errors.name = 'Name is required'
197
- if (!values.email) errors.email = 'Email is required'
198
- if (!values.message) errors.message = 'Message is required'
199
- return errors
208
+ validate: values => {
209
+ const errors = {};
210
+ if (!values.name) errors.name = 'Name is required';
211
+ if (!values.email) errors.email = 'Email is required';
212
+ if (!values.message) errors.message = 'Message is required';
213
+ return errors;
200
214
  },
201
- onSubmit: async (values) => {
202
- await submitForm(values)
203
- }
204
- })
215
+ onSubmit: async values => {
216
+ await submitForm(values);
217
+ },
218
+ });
205
219
 
206
220
  return (
207
221
  <form onSubmit={handleSubmit}>
208
222
  <input
209
- name="name"
223
+ name='name'
210
224
  value={values.name}
211
225
  onChange={handleChange}
212
226
  onBlur={handleBlur}
213
227
  className={touched.name && errors.name ? 'error' : ''}
214
228
  />
215
229
  {touched.name && errors.name && <span>{errors.name}</span>}
216
-
230
+
217
231
  <input
218
- name="email"
232
+ name='email'
219
233
  value={values.email}
220
234
  onChange={handleChange}
221
235
  onBlur={handleBlur}
222
236
  className={touched.email && errors.email ? 'error' : ''}
223
237
  />
224
238
  {touched.email && errors.email && <span>{errors.email}</span>}
225
-
239
+
226
240
  <textarea
227
- name="message"
241
+ name='message'
228
242
  value={values.message}
229
243
  onChange={handleChange}
230
244
  onBlur={handleBlur}
231
245
  className={touched.message && errors.message ? 'error' : ''}
232
246
  />
233
247
  {touched.message && errors.message && <span>{errors.message}</span>}
234
-
235
- <button type="submit" disabled={isSubmitting}>
248
+
249
+ <button type='submit' disabled={isSubmitting}>
236
250
  {isSubmitting ? 'Sending...' : 'Send Message'}
237
251
  </button>
238
252
  </form>
239
- )
253
+ );
240
254
  }
241
255
  ```
242
256
 
@@ -247,11 +261,11 @@ function ContactForm() {
247
261
  Access the previous value:
248
262
 
249
263
  ```tsx
250
- import { usePrevious } from '@foundrykit/hooks'
264
+ import { usePrevious } from '@foundrykit/hooks';
251
265
 
252
266
  function Counter() {
253
- const [count, setCount] = useState(0)
254
- const previousCount = usePrevious(count)
267
+ const [count, setCount] = useState(0);
268
+ const previousCount = usePrevious(count);
255
269
 
256
270
  return (
257
271
  <div>
@@ -259,7 +273,7 @@ function Counter() {
259
273
  <p>Previous: {previousCount}</p>
260
274
  <button onClick={() => setCount(count + 1)}>Increment</button>
261
275
  </div>
262
- )
276
+ );
263
277
  }
264
278
  ```
265
279
 
@@ -268,16 +282,13 @@ function Counter() {
268
282
  Set up intervals with automatic cleanup:
269
283
 
270
284
  ```tsx
271
- import { useInterval } from '@foundrykit/hooks'
285
+ import { useInterval } from '@foundrykit/hooks';
272
286
 
273
287
  function Timer() {
274
- const [seconds, setSeconds] = useState(0)
275
- const [isRunning, setIsRunning] = useState(false)
288
+ const [seconds, setSeconds] = useState(0);
289
+ const [isRunning, setIsRunning] = useState(false);
276
290
 
277
- useInterval(
278
- () => setSeconds(seconds + 1),
279
- isRunning ? 1000 : null
280
- )
291
+ useInterval(() => setSeconds(seconds + 1), isRunning ? 1000 : null);
281
292
 
282
293
  return (
283
294
  <div>
@@ -286,7 +297,7 @@ function Timer() {
286
297
  {isRunning ? 'Pause' : 'Start'}
287
298
  </button>
288
299
  </div>
289
- )
300
+ );
290
301
  }
291
302
  ```
292
303
 
@@ -297,78 +308,82 @@ function Timer() {
297
308
  Combine multiple hooks for complex functionality:
298
309
 
299
310
  ```tsx
300
- import { useLocalStorage, useDebouncedValue, useMediaQuery } from '@foundrykit/hooks'
311
+ import {
312
+ useLocalStorage,
313
+ useDebouncedValue,
314
+ useMediaQuery,
315
+ } from '@foundrykit/hooks';
301
316
 
302
317
  function useResponsiveSearch() {
303
- const [query, setQuery] = useLocalStorage('search-query', '')
304
- const debouncedQuery = useDebouncedValue(query, 300)
305
- const isMobile = useMediaQuery('(max-width: 768px)')
318
+ const [query, setQuery] = useLocalStorage('search-query', '');
319
+ const debouncedQuery = useDebouncedValue(query, 300);
320
+ const isMobile = useMediaQuery('(max-width: 768px)');
306
321
 
307
322
  const searchResults = useMemo(() => {
308
- if (!debouncedQuery) return []
309
- return performSearch(debouncedQuery, { limit: isMobile ? 5 : 10 })
310
- }, [debouncedQuery, isMobile])
323
+ if (!debouncedQuery) return [];
324
+ return performSearch(debouncedQuery, { limit: isMobile ? 5 : 10 });
325
+ }, [debouncedQuery, isMobile]);
311
326
 
312
327
  return {
313
328
  query,
314
329
  setQuery,
315
330
  debouncedQuery,
316
331
  searchResults,
317
- isMobile
318
- }
332
+ isMobile,
333
+ };
319
334
  }
320
335
  ```
321
336
 
322
337
  ### Hook with Dependencies
323
338
 
324
339
  ```tsx
325
- import { useClickOutside } from '@foundrykit/hooks'
340
+ import { useClickOutside } from '@foundrykit/hooks';
326
341
 
327
342
  function useDropdown(initialState = false) {
328
- const [isOpen, setIsOpen] = useState(initialState)
329
- const ref = useRef(null)
343
+ const [isOpen, setIsOpen] = useState(initialState);
344
+ const ref = useRef(null);
330
345
 
331
- useClickOutside(ref, () => setIsOpen(false))
346
+ useClickOutside(ref, () => setIsOpen(false));
332
347
 
333
- const open = useCallback(() => setIsOpen(true), [])
334
- const close = useCallback(() => setIsOpen(false), [])
335
- const toggle = useCallback(() => setIsOpen(!isOpen), [isOpen])
348
+ const open = useCallback(() => setIsOpen(true), []);
349
+ const close = useCallback(() => setIsOpen(false), []);
350
+ const toggle = useCallback(() => setIsOpen(!isOpen), [isOpen]);
336
351
 
337
352
  return {
338
353
  isOpen,
339
354
  ref,
340
355
  open,
341
356
  close,
342
- toggle
343
- }
357
+ toggle,
358
+ };
344
359
  }
345
360
  ```
346
361
 
347
362
  ### Performance Optimization
348
363
 
349
364
  ```tsx
350
- import { useDebouncedValue } from '@foundrykit/hooks'
365
+ import { useDebouncedValue } from '@foundrykit/hooks';
351
366
 
352
367
  function OptimizedSearch() {
353
- const [query, setQuery] = useState('')
354
- const debouncedQuery = useDebouncedValue(query, 500)
368
+ const [query, setQuery] = useState('');
369
+ const debouncedQuery = useDebouncedValue(query, 500);
355
370
 
356
371
  // Memoize expensive operation
357
372
  const searchResults = useMemo(() => {
358
- if (!debouncedQuery) return []
359
- return expensiveSearch(debouncedQuery)
360
- }, [debouncedQuery])
373
+ if (!debouncedQuery) return [];
374
+ return expensiveSearch(debouncedQuery);
375
+ }, [debouncedQuery]);
361
376
 
362
377
  return (
363
378
  <div>
364
379
  <input
365
380
  value={query}
366
- onChange={(e) => setQuery(e.target.value)}
367
- placeholder="Search..."
381
+ onChange={e => setQuery(e.target.value)}
382
+ placeholder='Search...'
368
383
  />
369
384
  <SearchResults results={searchResults} />
370
385
  </div>
371
- )
386
+ );
372
387
  }
373
388
  ```
374
389
 
@@ -377,14 +392,14 @@ function OptimizedSearch() {
377
392
  All hooks include comprehensive TypeScript definitions:
378
393
 
379
394
  ```tsx
380
- import { useLocalStorage, useDebouncedValue } from '@foundrykit/hooks'
395
+ import { useLocalStorage, useDebouncedValue } from '@foundrykit/hooks';
381
396
 
382
397
  // Type-safe localStorage hook
383
- const [user, setUser] = useLocalStorage<User>('user', null)
398
+ const [user, setUser] = useLocalStorage<User>('user', null);
384
399
 
385
400
  // Type-safe debounced value
386
- const [searchTerm, setSearchTerm] = useState<string>('')
387
- const debouncedSearchTerm = useDebouncedValue<string>(searchTerm, 300)
401
+ const [searchTerm, setSearchTerm] = useState<string>('');
402
+ const debouncedSearchTerm = useDebouncedValue<string>(searchTerm, 300);
388
403
  ```
389
404
 
390
405
  ## Best Practices
@@ -394,13 +409,13 @@ const debouncedSearchTerm = useDebouncedValue<string>(searchTerm, 300)
394
409
  ```tsx
395
410
  // ✅ Good - Stable callback
396
411
  const handleClick = useCallback(() => {
397
- console.log('clicked')
398
- }, [])
412
+ console.log('clicked');
413
+ }, []);
399
414
 
400
415
  // ❌ Avoid - Unstable callback
401
416
  const handleClick = () => {
402
- console.log('clicked')
403
- }
417
+ console.log('clicked');
418
+ };
404
419
  ```
405
420
 
406
421
  ### Cleanup
@@ -410,17 +425,17 @@ const handleClick = () => {
410
425
  useEffect(() => {
411
426
  const timer = setTimeout(() => {
412
427
  // do something
413
- }, 1000)
414
-
415
- return () => clearTimeout(timer)
416
- }, [])
428
+ }, 1000);
429
+
430
+ return () => clearTimeout(timer);
431
+ }, []);
417
432
 
418
433
  // ❌ Avoid - Missing cleanup
419
434
  useEffect(() => {
420
435
  setTimeout(() => {
421
436
  // do something
422
- }, 1000)
423
- }, [])
437
+ }, 1000);
438
+ }, []);
424
439
  ```
425
440
 
426
441
  ### Performance
@@ -428,11 +443,11 @@ useEffect(() => {
428
443
  ```tsx
429
444
  // ✅ Good - Memoized expensive operations
430
445
  const expensiveValue = useMemo(() => {
431
- return computeExpensiveValue(data)
432
- }, [data])
446
+ return computeExpensiveValue(data);
447
+ }, [data]);
433
448
 
434
449
  // ❌ Avoid - Recomputing on every render
435
- const expensiveValue = computeExpensiveValue(data)
450
+ const expensiveValue = computeExpensiveValue(data);
436
451
  ```
437
452
 
438
453
  ## Contributing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foundrykit/hooks",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "eslint": "^9.0.0",
29
29
  "tsup": "^8.0.0",
30
30
  "typescript": "^5.9.2",
31
- "@foundrykit/eslint-config": "0.1.1",
32
- "@foundrykit/typescript-config": "0.1.1"
31
+ "@foundrykit/eslint-config": "0.2.1",
32
+ "@foundrykit/typescript-config": "0.1.2"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "react": "^19.1.1",
@@ -1,18 +0,0 @@
1
-
2
- 
3
- > @foundrykit/hooks@0.1.0 build /Users/isaacsneddon-jenkins/Desktop/projects/umi/projects/foundrykit/packages/hooks
4
- > tsup
5
-
6
- CLI Building entry: src/index.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.5.0
9
- CLI Using tsup config: /Users/isaacsneddon-jenkins/Desktop/projects/umi/projects/foundrykit/packages/hooks/tsup.config.ts
10
- CLI Target: es2022
11
- CLI Cleaning output folder
12
- ESM Build start
13
- ESM dist/index.js 2.49 KB
14
- ESM dist/index.js.map 4.72 KB
15
- ESM ⚡️ Build success in 136ms
16
- DTS Build start
17
- DTS ⚡️ Build success in 3352ms
18
- DTS dist/index.d.ts 546.00 B
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > @foundrykit/hooks@0.1.0 lint /Users/isaacsneddon-jenkins/Desktop/projects/umi/projects/foundrykit/packages/hooks
4
- > eslint . --max-warnings 0
5
-
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > @foundrykit/hooks@0.1.0 type-check /Users/isaacsneddon-jenkins/Desktop/projects/umi/projects/foundrykit/packages/hooks
4
- > tsc --noEmit
5
-