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

87
Views
React.js state update is delayed

I'm working on an input box that takes a value for labor, sets it as state and then later does calculations based on the number. However, I'm running into an issue where the state seems to be updating with a delay to the input. I have two other inputs that are structured similarly and not having the issue. I'm not sure what is causing this.

Here is the output seen when comparing console.log(labor) with console.log(e.target.value) (found in the second code block).

Output seen when comparing console.log(labor) with ```console.log(e.target.value) (found in the second code block).

function ProductCalculator() {
    const [labor, setLabor] = useState(70);

return (
        <div>
            <ProjectSelector
                labor={labor}
                setLabor={setLabor}
    />
    );
}

function ProjectSelector({
    labor,
    setLabor,
}) {
    function LaborInput() {
        const [name, setName] = useState("");

        function handleChange(e) {
            setName(parseFloat(e.target.value));
            setLabor(parseFloat(e.target.value));
            console.log(e.target.value); //value is correct
            console.log(labor); //value is delayed 
            
        }

        return (
            <div className="col-xs-2" id="labor-input">
                Hourly Labor Rate
                <input type="number" onChange={handleChange} value={labor} />
            </div>
        );
    }
    
    return (
        <div" className="row">
            <div>{LaborInput()}</div>
        </div>
    );
}

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!