useUndoState
About
Drop in replacement for useState hook but with undo functionality.
Examples
Basic usage
Any kind of value
You can pass any kind of value to hook just like React's own useState.
Setter function is still the same
Setter function can also be used with callback just like React's own useState.
Max undo stack size
To preserve memory you can limit number of steps that will be preserved in undo history.
Arguments
Arguments | Type | Description | Default value |
---|---|---|---|
initialValue | boolean | Initial value of the state | false |
Options | Object | An options object for the hook | {maxSize: 100} |
Note: The second argument is an options object which currently accepts a maxSize which governs the maximum number of previous states to keep track of.
Returned array items
Returned Array items | Type | Description |
---|---|---|
value | Any | Current value |
setValue | function | Setter function to update value |
undo | function | Undo state value |