Skip to content

return () => clearInterval(intervalId) #13

Open
@andy27182

Description

@andy27182

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])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions