Appearance
useStateAutoReset
A controllable state which will be reset to the default value after some time.
Demo
Usage
tsx
import { useStateAutoReset } from '@reause/shared'
const [message, setMessage] = useStateAutoReset('default message', 1000)
function handleMessage() {
// here the value will change to 'message has set' but after 1000ms, it will change to 'default message'
setMessage('message has set')
}NOTE
You can reassign the entire object to trigger updates after making deep mutations to the inner value.
Type Declarations
ts
export type UseStateAutoResetReturn<T = any> = [
T,
Dispatch<SetStateAction<T>>
]
export type State<T> = StateValue<T>
export function useStateAutoReset<T = any>(defaultValue: State<T>, afterMs?: number): UseStateAutoResetReturn<T>
export function useControllableState<T>(state: State<T>, options?: UseControllableStateOptions<T>): StateTuple<T>