Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
React state not being changed after passed down from parent

I a setState function being passed down from a parent component, I want to setTheState of the parent setter if the enterKey is pressed. Though, when I set the state nothing happens and I'm still left with an empty array

Here's the code snippet

const { check, setCheck } = props // receive from props
const callApi = async (onEnter) => {
  const res = await callFunction('', data)
  if (res) {
    setResults(res)
    if (onEnter) {
      setCheck(res)
      console.log('check', check) // returns []
    }
  }

Returns [] when I log in parent as well

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Instead of console logging it immediately, wait for it to change, because it's an async operation. You can wrap your log in a useEffect:

useEffect(() => {
    console.log(check);
}, [check]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda