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

313
Views
Cómo solucionar el problema con el estado que no es igual al estado actual

Estoy llamando a una función que usa el estado, pero el estado que se usa en la función es el estado anterior, aunque si usa el depurador de reacción en Chrome, muestra el estado nuevo.

 const [somevalue,setsomevalue] = useState("newstate") function myfunction() { console.log(somevalue) } myfunction()

producción:

 oldstate

Estaba pensando en usar forceUpdate() pero estoy usando un componente sin clases.

 const CauseCodeChangeHandler = (e) => { setSelectedCauseCode(e.target.value); }; const serQtyChangeHandler = (e) => { if (SelectedCauseCode == "CUS") { } else if (SelectedCauseCode == "OPS") { } else if (SelectedCauseCode == 'OOW') { } }

mi componente:

 <ServiceSelectInput changeHandler={CauseCodeChangeHandler}/>

Está usando el antiguo CauseCode, no uno que acabo de seleccionar.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Este es el problema del cierre obsoleto y es algo queuseCallback está diseñado para abordar:

 import {useCallback, useState} from 'react'; function Component () { const [someValue, setSomeValue] = useState('newstate'); // This will make sure that `myFunction` is recreated // every time that `someValue` changes const myFunction = useCallback(() => console.log(someValue), [someValue]); // ...rest of component }
about 4 years ago · Juan Pablo Isaza Report
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!