Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
Interval not being cleared

I'm using a ref to set an interval that's checking a buffer state of a media element.

The interval is successfully set, however, it's not being cleared.

enter image description here

  const keepCheckingBuffer = useCallback(
    () => {
      const targetRef = !hasVideo ? audioRef.current : vidRef.current;
      console.log(targetRef.readyState, targetRef.HAVE_FUTURE_DATA);
      console.log('keep checking buffer');

      if (targetRef.readyState <= targetRef.HAVE_FUTURE_DATA) {
        bufferCheckInterval.current = setInterval(() => {
          console.log('im running and interval!!!');

          if (targetRef.readyState > targetRef.HAVE_FUTURE_DATA) {
            setIsBuffered(true);
            setIsVideoReadyToPlay(true);
          }
        }, 1000);
        console.log('not buffering, setInterval');
      } else {
        console.log('clearInterval');
        clearInterval(bufferCheckInterval.current);
      }
    },

    [audioRef, vidRef, hasVideo],
  );

I'd prefer not to use a useEffect since my component rerenders a lot (it is expected) and I don't want to tie the triggering to a state inside the dependecy array.

I also tried to remove the useCallback hook.

Thanks all,

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!