use-undo
use-undo copied to clipboard
Doesn't handle evaluable functions on set/redo
Typically with useState, the setState function accepts either a value to set as the new state, or a function which can transform the old state to the new state. Using the function is safer as it can gracefully handles multiple setState calls in succession. To handle this, the set and redo function needs to check the type of newPresent, and if it is a function apply it to the old present to get newPresent.
I've came here because I have a use case that requires exactly the same functionality.
The use-undo have an small design defect and is that it doesn't take into account "clojured" hooks. Basically we have no way to retrieve the "real current state" and it miss the fact that state mutations are async by conception.
There are two ways of handling this:
- Allowing the usage of a custom "reducer" function like they do in this example
- Allowing the system to pass a function as well and send to that function the current value of the state in the reducer. cc: @homerchen19