Skip to content

Commit

Permalink
feat(useInterval): add reset function (#2686)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammad Agbareya <muhammed@irestweb.com>
  • Loading branch information
mohammadhosry and MohammadAgbareya committed Feb 18, 2023
1 parent 111892e commit 81db660
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/shared/useInterval/index.md
Expand Up @@ -16,5 +16,5 @@ const counter = useInterval(200)
```

```ts
const { counter, pause, resume } = useInterval(200, { controls: true })
const { counter, reset, pause, resume } = useInterval(200, { controls: true })
```
2 changes: 2 additions & 0 deletions packages/shared/useInterval/index.ts
Expand Up @@ -41,6 +41,7 @@ export function useInterval(interval: MaybeComputedRef<number> = 1000, options:

const counter = ref(0)
const update = () => counter.value += 1
const reset = () => counter.value = 0
const controls = useIntervalFn(callback
? () => {
update()
Expand All @@ -51,6 +52,7 @@ export function useInterval(interval: MaybeComputedRef<number> = 1000, options:
if (exposeControls) {
return {
counter,
reset,
...controls,
}
}
Expand Down

0 comments on commit 81db660

Please sign in to comment.