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

[Feat] useObservableState proposal #2710

Open
ali-garajian opened this issue Dec 30, 2024 · 0 comments
Open

[Feat] useObservableState proposal #2710

ali-garajian opened this issue Dec 30, 2024 · 0 comments

Comments

@ali-garajian
Copy link

ali-garajian commented Dec 30, 2024

I've found this hook to be quite useful.
The interface would be something like this

const { state, set, useValue, useOnChange } = useObservableState('initial_value');

// state.current -> current value of the state
// set -> sets the new value of the state and notifies all listeners
// useValue -> registers a listener and returns a state that causes rerender 
// useOnChange -> registers a listener and accepts a callback that gets called on updates

If you're interested I could send a PR

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

1 participant