Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't handle evaluable functions on set/redo #19

Open
gorj-tessella opened this issue Mar 12, 2021 · 1 comment
Open

Doesn't handle evaluable functions on set/redo #19

gorj-tessella opened this issue Mar 12, 2021 · 1 comment

Comments

@gorj-tessella
Copy link

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 gorj-tessella changed the title Doesn't handle Doesn't handle evaluable functions on set/redo Mar 12, 2021
@carlesnunez
Copy link

carlesnunez commented Aug 6, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants