use-undo icon indicating copy to clipboard operation
use-undo copied to clipboard

Doesn't handle evaluable functions on set/redo

Open gorj-tessella opened this issue 3 years ago • 1 comments

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.

gorj-tessella avatar Mar 12 '21 14:03 gorj-tessella

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:

  1. Allowing the usage of a custom "reducer" function like they do in this example
  2. 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

carlesnunez avatar Aug 06 '21 11:08 carlesnunez