use-good-hooks 1.0.15 โ†’ 1.0.17

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/README.md CHANGED
@@ -362,6 +362,29 @@ const MyComponent = () => {
362
362
  - `state`: The component's local copy of the state
363
363
  - `setState`: Function to update global state (accepts new value or update function)
364
364
 
365
+ ### `useTemporaryState`
366
+
367
+ Creates a temporary state that resets after a specified timeout.
368
+
369
+ ```typescript
370
+ import { useTemporaryState } from 'use-good-hooks/use-temporary-state';
371
+
372
+ const [state, setState] = useTemporaryState('initial', 1000);
373
+
374
+ // State will reset to 'initial' after 1 second
375
+ ```
376
+
377
+ #### Parameters
378
+
379
+ - `initialState`: The initial state value
380
+ - `timeout`: The timeout duration in milliseconds (default: 3000)
381
+
382
+ #### Returns
383
+
384
+ - Array with:
385
+ - `state`: The current state
386
+ - `setState`: Function to update state
387
+
365
388
  ## ๐Ÿงช Running Tests
366
389
 
367
390
  This library is thoroughly tested with Vitest and React Testing Library. To run the tests:
@@ -385,6 +408,8 @@ Each hook in this library is designed with performance in mind:
385
408
  2. `useDistinct` avoids reference equality problems with optional deep comparison
386
409
  3. `useStorageState` batches storage updates to reduce expensive serialization/deserialization
387
410
  4. `useUrlState` efficiently handles URL synchronization with debouncing
411
+ 5. `useGlobalState` and `createGlobalState` provide a way to share state across components with automatic synchronization
412
+ 6. `useTemporaryState` allows for temporary state that resets after a timeout
388
413
 
389
414
  ## ๐Ÿ› ๏ธ Development
390
415
 
@@ -0,0 +1,7 @@
1
+ import { Dispatch } from 'react';
2
+ import { SetStateAction } from 'react';
3
+
4
+ declare const useTemporaryState: <T>(initialState: T, timeout: number) => (T | Dispatch<SetStateAction<T>>)[];
5
+ export default useTemporaryState;
6
+
7
+ export { }
@@ -0,0 +1,12 @@
1
+ import { useRef as o, useState as c, useEffect as n } from "react";
2
+ const m = (e, r) => {
3
+ const t = o(null), [u, s] = c(e);
4
+ return n(() => (clearTimeout(t.current), t.current = setTimeout(() => {
5
+ s(e);
6
+ }, r), () => {
7
+ clearTimeout(t.current);
8
+ }), [e, u, r]), [u, s];
9
+ };
10
+ export {
11
+ m as default
12
+ };
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "test": "vitest",
50
50
  "test:coverage": "vitest --coverage"
51
51
  },
52
- "version": "1.0.15"
52
+ "version": "1.0.17"
53
53
  }