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

116
Vistas
How to get checkbox value immediately after setting the state in react

I want the checkbox value immediately after setting the state. on the below code i want the checkbox value inside the handelchange after setting the state I have added console over there

state = {
status: false,
}

handleChange = (event) => {
this.setState((prevState) => {
   return {
      ...prevState,
      status: !prevState.status
   }
})
 ====console.log(this.state.status)====//if it checked and set i should get true
 }


<Form.Check
type="checkbox" 
label="Consigne temporaire"
value={this.state.status}
onChange={this.handleChange}
 />
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use useEffect or componentDidUpdate and bind the checkbox state with it.

state = {
status: false,
}

componentDidUpdate(prevProps, prevState) {
  if (prevState.status !== this.state.status) {
    console.log('Checkbox State change',this.state.status)
  }
}

handleChange = (event) => {
this.setState((prevState) => {
   return {
      ...prevState,
      status: !prevState.status
   }
})
 ====console.log(this.state.status)====//if it checked and set i should get true
 }


<Form.Check
type="checkbox" 
label="Consigne temporaire"
value={this.state.status}
onChange={this.handleChange}
 />
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can pass a callback as the second argument to this.setState, which is guaranteed to run after the state has been updated (see the docs on setState)

this.setState((prevState) => {
  return {
     ...prevState,
     status: !prevState.status
  }
}, () => {
  console.log(this.state.status)
})
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