Skip to content

Commit

Permalink
refactor(use-interval): not call immediate when delay is falthy
Browse files Browse the repository at this point in the history
  • Loading branch information
namepain committed Dec 28, 2019
1 parent 1269a82 commit c3a98ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@namepain/hooks",
"version": "0.0.1-development",
"version": "0.0.3",
"description": "",
"keywords": [
"react hooks"
Expand Down
8 changes: 4 additions & 4 deletions src/useInterval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useEffect } from 'react'
import { useRef, useEffect, useCallback } from 'react'

interface SaveRef {
fn: () => any
Expand All @@ -19,7 +19,7 @@ export default function useInterval(

useEffect(() => {
saved.current.fn = callback
if (immediate) {
if (immediate && delay) {
saved.current.fn()
}
}, [callback, immediate])
Expand All @@ -40,7 +40,7 @@ export default function useInterval(
}
}, [delay])
return {
stop: () => clearTimeout(saved.current.timer),
resume: () => saved.current.loop && saved.current.loop()
stop: useCallback(() => clearTimeout(saved.current.timer), []),
resume: useCallback(() => saved.current.loop && saved.current.loop(), [])
}
}

0 comments on commit c3a98ff

Please sign in to comment.