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

137
Views
Why does my use state does not update even after using prevState? Is useEffect the only way?

I understand useState does not update instantly. Some of the tutorial videos on react shows use of callback function as a way to achieve the result for immediate update. I tried that but it doesnt seem working .attaching the sample code

import { useState } from "react";
const testComponent = () => {
    const [userInputs, setUserInputs] = useState({
        age: '',
        comments: ''
    })

    function commentInputHandler(event) {
        setUserInputs((prevState) => {
            return {
                ...prevState,
                comments: event.target.value
            }
        })
        console.log(userInputs.comments)
    }
    render(
        <textarea onChange={commentInputHandler} className="form-control" required ></textarea>
    )
}
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!