TipHighly useful for complex forms or filters. Instead of manually setting every field back to its default, a single call to reset() restores the state to its exact initialState.
The useResettableState is a specialized wrapper around useState that captures the initial value upon the first render. It provides an explicit reset function that, when called, restores the state to its original provided value, regardless of subsequent updates.
This hook is particularly useful for managing temporary inputs, filters, or complex forms when a Discard Changes or Reset to Default feature is required. It handles both direct values and lazy initialization functions identically to the native useState API.
| Name | Type | Description |
|---|---|---|
| initialState | T Generic | (() => T Generic) | The initial state value or a function that returns the initial value. |
| Name | Type | Description |
|---|---|---|
| state | T Generic | The current state value. |
| setState | Dispatch<SetStateAction<T Generic>> | The standard React function to update the state. |
| reset | () => void | A memoized function that resets the state to the capture initial value. |
{
"category": "all",
"query": "",
"sortBy": "relevance"
}