useReducerGetReset
Custom useReducer with get and reset state functions.
Demo
INFO
The implementation is like that useStateGetReset but built on useReducer.
Please visit useStateGetReset example to see how it works.
Types
UseReducerGetResetProps
@templateR - The reducer type, extendingReducer<any, any>.
Parameters accepted by useReducerGetReset.
| Property | Type | Required | Description |
|---|---|---|---|
reducer | R | ✓ | The reducer function (state, action) => state that computes the next state given the current state and a dispatched action. |
initialState | ReducerState<R> | ✓ | The initial reducer state value, passed directly to useReducer. |
initializer | (init: ReducerState<R>) => ReducerState<R> | An optional initializer function that receives initialState and returns the actual initial state. Useful for lazily computing the initial value or extracting it from a larger object. |
UseReducerGetResetResult
@templateR - The reducer type.
Return value of useReducerGetReset.
| Index | Type | Description |
|---|---|---|
[0] | ReducerState<R> | The current reducer state, reactive — triggers a re-render when updated. |
[1] | Dispatch<ReducerAction<R>> | The stable dispatch function used to send actions to the reducer. |
[2] | () => ReducerState<R> | A stable getter that returns the current reducer state synchronously without causing a re-render. Useful for reading state inside callbacks without adding it as a dependency. |
[3] | () => void | Resets the reducer state back to the original initialState (after applying initializer if provided), dispatching a reset internally and triggering a re-render. |
