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

105
Visualizações
Material UI checkbox toggle value based off input from object

I have an unchecked checkbox. I am trying to change the value of it based off of data from an object. The object is from an SQL select boolean column 'T' or 'F'. If the value is 'T' then the box would be checked vise versa. I tried using a useState() that viewed the value but that didn't work.

  const [checkBoxState, setCheckBoxState] = React.useState(false);
  //check to see if values are 't' or 'f' to change them to vaiable formats
  function handleCheckState(databaseCondition) {
    if (databaseCondition == "T") {
      setCheckBoxState = true;
    }
    console.log(checkBoxState);
    return checkBoxState;
  }

This is the useState() I tried using.

<Checkbox checked={handleCheckState(data["validcycle"])} />

Here is the checkbox I want to toggle on/off based off that sql column.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Friend, you forgot to enclose hook in brackets, example : setState(value)

    const [checkBoxState, setCheckBoxState] = React.useState(false)

    function handleCheckState(databaseCondition) {
        if (databaseCondition == 'T') setCheckBoxState(true)
        else setCheckBoxState(false)
        return checkBoxState
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

you must change the state using:

setCheckBoxState(true);

instead of:

setCheckBoxState = true;

the better approach is simply like this:

<Checkbox checked={databaseCondition === "T"} />
about 4 years ago · Juan Pablo Isaza 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