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

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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