use-good-hooks 1.0.16 โ 1.0.18
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 +25 -0
- package/dist/use-temporary-state.d.ts +1 -1
- package/package.json +1 -1
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
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch } from 'react';
|
|
2
2
|
import { SetStateAction } from 'react';
|
|
3
3
|
|
|
4
|
-
declare const useTemporaryState: <T>(initialState: T, timeout: number) =>
|
|
4
|
+
declare const useTemporaryState: <T>(initialState: T, timeout: number) => readonly [T, Dispatch<SetStateAction<T>>];
|
|
5
5
|
export default useTemporaryState;
|
|
6
6
|
|
|
7
7
|
export { }
|
package/package.json
CHANGED