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

53
Views
useState too slow for video streaming useInterval

Every 33 milliseconds, I want to record changes made to a form element. I need this done every 33 milliseconds, because I am attempting to record a "video" of a form element by recording changes to the form element every 33 milliseconds. On a separate page, I will render these changes every 33 milliseconds, giving the illusion of a video.

I need to use the useState hook in React. On diagnosing, I have found that useState is so slow that I cannot use it to record changes the 33ms interval. When I rapidly type text into the form element, it lags considerably.

Is there a way I can record changes to the form element every 33 milliseconds using React? I can think of three ways - finding a suitable alternative to useState, using a more native video streaming solution, some form of javascript multi-threading. Please help me.


import React, { useState, useEffect } from 'react'

const store = []

const Record2 = (props) => {
  const [seconds, setSeconds] = useState(0)
  const [data, setData] = useState("")
  const [capturing, setCapturing] = React.useState(false);
  const handleChange = (e) => {
    setData(e.target.value)
  }
  const handleClick = (e) => {
    setCapturing(oldCapturing => !oldCapturing)
  }
  useEffect(() => {
    console.log("store", store)
    const interval = setInterval(() => {
      if (capturing) {
        setSeconds(seconds => seconds + 0.033);
        store.push({ seconds, data })
        console.log(store)
      }
    }, 33);

    return () => clearInterval(interval);
  });

  return (
    <div>
      <input onChange={handleChange} value={data}></input>
      <button onClick={handleClick}>{capturing ? "end capture" : "start capture"}</button>
    </div>
  )
}

export default Record2




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!