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

Add useUndoRedo react hook for component-scoped observables #351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hugocxl
Copy link

@hugocxl hugocxl commented Aug 23, 2024

Hi 👋
I noticed there is no specific implementation for undo/redo in component-scoped observables.

This PR adds a hook that keeps track of changes in a local observable and provide a set of functions that allow for navigating the history back and forth.

Example:

function Component() {
   const obs$ = useObservable()
   const { undo, redo, undos$, redos$, history$ } = useUndoRedo(obs$)
   
   return ( ... )
}

The implementation is based on undoRedo from this same lib, but making it compatible with a local-state case.
Not sure if I followed all codebase conventions properly, please let me know otherwise.


PD: Thanks for this incredible lib ❤️

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

Successfully merging this pull request may close these issues.

1 participant