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 timeout methods #136

Merged
merged 3 commits into from Feb 13, 2023
Merged

Add timeout methods #136

merged 3 commits into from Feb 13, 2023

Conversation

evgenykuzyakov
Copy link
Contributor

Fixes: #76

This PR also adds ability to update state by passing a function.

Adds four methods:

  • setTimeout
  • clearTimeout
  • setInterval
  • clearInterval

Note, that within setInterval, the state is not being updated properly: https://eight-bites.blog/en/2021/05/setinterval-setstate/

if (state === undefined) {
  State.init({
    counter: 0,
  });
  setInterval(() => {
    State.update((state) => ({
      ...state,
      counter: state.counter + 1,
    }));
  }, 100);
}

return <div>Hello World {state.counter}</div>;

@evgenykuzyakov evgenykuzyakov merged commit eaf6388 into master Feb 13, 2023
@evgenykuzyakov evgenykuzyakov deleted the setTimeout branch February 13, 2023 17:46
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.

Add setTimeout and setInterval
1 participant