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

133
Views
React Hooks update state immediately

I want to explain it basically. This is not my code. It just for explain my issue. I know I can use the name parameter when I sending API requests but it's not my question.

const [deviceName, setDeviceName] = useState("iPad");

const changeDeviceName = (name) => {
     setDeviceName(name);
     sendNameToAPI(deviceName);
}

return (
    <div>
         <p>{deviceName}</p>
         <button  onClick={() => { changeDeviceName("iPhone"); }}>
    </div>
)

When setDeviceName works. In HTML deviceName change. It's OK but I want to use deviceName somewhere else in JS its coming "iPad". What can I do? Why? I research a lot I can't find to best practice. Someone say useEffect but If I have a lot of states it's mean a lot useEffect.

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!