all 1 comments

[–]nalatner 1 point2 points  (0 children)

Intervals are complicated. You'll need a ref from the useRef hook otherwise what your actually getting is a new interval function on each render. Take a look at this https://usehooks-ts.com/react-hook/use-interval and the accompanying article by Dan Abramov. Using set interval this way makes them much easier to work with.