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

return () => clearInterval(intervalId) #13

Open
andy27182 opened this issue Jan 28, 2024 · 0 comments
Open

return () => clearInterval(intervalId) #13

andy27182 opened this issue Jan 28, 2024 · 0 comments

Comments

@andy27182
Copy link

Hi, I'm studying your videos, thanks a lot, but when I started the Code.tsx part, there is a little doubt that return () => clearInterval(intervalId) is used as the return value of the callback function for setTimeout. I think it will not work and should it be used as the return value of the useEffect callback function for clearing the memory.

useEffect(() => {
    if (show && animated) {
      let i = 0
      setTimeout(() => {
        const intervalId = setInterval(() => {
          setText(code.slice(0, i))
          i++
          if (i > code.length) {
            clearInterval(intervalId)
          }
        }, 15)

        return () => clearInterval(intervalId)
      }, animationDelay || 150)
    }
  }, [code, show, animated, animationDelay])
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

No branches or pull requests

1 participant