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

Reset method with useStatewithHistory #1386

Open
jinixx opened this issue Jul 24, 2020 · 0 comments
Open

Reset method with useStatewithHistory #1386

jinixx opened this issue Jul 24, 2020 · 0 comments

Comments

@jinixx
Copy link

jinixx commented Jul 24, 2020

Is your feature request related to a problem? Please describe.
Provide a method to reset history to initial value. It can also reset to a new initial history and at the same time, can be used to set a new initial value.

Imagine a game board, the user can restart (reset) or the user can change some board config, and we can reset to a new initial board value.

Describe the solution you'd like

const [ state, setState, { reset } ] = useStateWithHistory('initial');

setState('one');
// state is now 'one', history is ['initial', 'one'], position is 1

// reset to initial
reset();
// state is now 'initial', history is ['initial'], position is 0

setState('two');
// state is now 'two', history is ['initial', 'two'], position is 1

reset(['one', 'two', 'three']);
// state is now 'three', history is ['one', 'two', 'three'], position is 2
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