Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!