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

Feature/10 add usetimeout and useinterval hooks #16

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

larsvanbraam
Copy link
Contributor

@larsvanbraam larsvanbraam commented Apr 26, 2022

This PR will add the following hooks:

  • useInterval
  • useTimeout

and close #10

@larsvanbraam larsvanbraam requested review from ThaNarie and psimk April 26, 2022 12:29
src/useInterval/useInterval.stories.mdx Show resolved Hide resolved
src/useInterval/useInterval.stories.ts Outdated Show resolved Hide resolved
src/useInterval/useIntervalStories.test.ts Outdated Show resolved Hide resolved
src/useInterval/useInterval.test.ts Show resolved Hide resolved
src/useInterval/useInterval.ts Outdated Show resolved Hide resolved
src/useTimeout/useTimeout.stories.ts Outdated Show resolved Hide resolved
src/useTimeout/useTimeout.test.utils.ts Outdated Show resolved Hide resolved
clearTimeout(handle);
}

onUnmounted(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If onUnmounted expects a function definition maybe we could write it like:

onUnmounted(cancel)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I don't like these kind of optimisations:

  • When not careful, you could lose scope of the passed function
  • When not careful, you could be passing unwanted arguments to the passed function
  • And some more subjective reasons, like clarity, and not having to add/remove the arrow function when wanting to add more lines, etc.

clearInterval(handle);
}

onUnmounted(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as here
This could be

onUnmounted(stop)

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 useTimeout and useInterval hooks
4 participants