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

111
Vistas
How do i set sate based on the condition in checkbox Change function reactjs

In the checkbox the default value is null and I am setting it as true when required but also I thought of one more condition that needs to be set when the checkbox is already selected I want to unselect it and set the value as false instead of null.

Assume alwaysSelected -if this is selected it is true(onload) based on this condition i should update the state

this.state = {
checkbox: null,
}
this.props.alwaysSelected=true

<Checkbox
onChange={this.ChangeValue}
/>

ChangeValue= (event) => {
this.setState(checboxState=> ({
checkbox: checboxState.checkbox ? null : true
});
})

Just say prevState.checkbox -true on a load of the page then it just gives null but need to set it as false

Option tried is setState callback and componentDidUpdate but failed to acheive.

can we do this in another approach??

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

0

You can pass the checkbox state to the Checkbox component as value and change the event:

ChangeValue = () => this.setState({checkbox:!checkbox});

or if event returns true/false

 ChangeValue = event => this.setState({checkbox:!event});
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