Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda