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

102
Vistas
How to set default state in checkbox when it is not checked- React

I am trying to set the default value of the check box when the check box is unchecked

Initial state

  this.state = {
  checkbox: null,
}

<Checkbox
 onChange={this.ChangeValue}
 />

 ChangeValue= (event) => {
this.setState(
  (prevState) => ({
    checkbox: !prevState.checkbox,
  })
})

When I click on the checkbox it sets to true which is fine when I unselect/uncheck the checkbox I need to set it to the default state value(null) instead of false

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If you want the value to alternate between true and null that can be done like this:

this.setState(prevState => ({
  checkbox: prevState.checkbox ? null : true
});
about 4 years ago · Santiago Trujillo 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