Skip to content
This repository has been archived by the owner on Jul 23, 2022. It is now read-only.

useEffect to clearTimeout dependency array? #3

Closed
crobinson42 opened this issue Jun 11, 2020 · 1 comment · Fixed by #4
Closed

useEffect to clearTimeout dependency array? #3

crobinson42 opened this issue Jun 11, 2020 · 1 comment · Fixed by #4
Labels
bug Something isn't working

Comments

@crobinson42
Copy link

Why is the hook not using the dependency array 2nd arg in useEffect here: https://github.com/DrugoLebowski/use-throttled-callback/blob/develop/src/use-throttled-callback.ts#L42

I think what you want is this:

useEffect(() => {
    return () => {
      clearTimeout(timeoutId.current)
    }
  }, [])

When you omit the 2nd arg in useEffect, you are clearing the timeout every time the hook is fired (including when components and parent components re-render)

@DrugoLebowski
Copy link
Owner

Hey @crobinson42. I have to be honest, I wrote this hook some time ago when my experience on React was not so high. Anyway, thanks to having pointed out that issue. I'll try to resolve it as soon as possible if you need it.

DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
DrugoLebowski added a commit that referenced this issue Jun 11, 2020
@DrugoLebowski DrugoLebowski added the bug Something isn't working label Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 12, 2020
DrugoLebowski added a commit that referenced this issue Jun 13, 2020
DrugoLebowski added a commit that referenced this issue Jun 13, 2020
DrugoLebowski added a commit that referenced this issue Jun 13, 2020
DrugoLebowski added a commit that referenced this issue Jun 13, 2020
DrugoLebowski added a commit that referenced this issue Jun 13, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
DrugoLebowski added a commit that referenced this issue Jun 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants