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

243
Views
Material UI Checkbox not toggling on and off

Im not exactly sure what's going on because in the Material UI docs, it seems pretty simple, but I can't get my checkbox to toggle either on or off after I create the component.

const createCheckBox = (row, checkBoxStatus, changeStatus) => {
    let text = "";
    if (row.values.map((value, index) => {
        text += value.title
    }))
        if (text) {
            return (
                <Checkbox checked />
            )
        } else {
            return (
                <Checkbox checked={false} disabled />
            )
        }
}

I'm creating new checkboxes for a set number of rows. Each row has a text value, and there's text, I want to be able to toggle the row's checkbox on or off, but if there's no text, I want the box to be disabled and not checked marked.

I weird thing is, that if I remove the checked from the true portion of the code, i can toggle the checkbox but can't when I set it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't know why but after I ask these questions I'm usually able to figure it out myself after asking them.

Here's what I got.

I set the true condition to this

<Checkbox defaultChecked />

But then it gave me this error.

MUI: A component is changing the default checked state of an uncontrolled SwitchBase after being initialized. To suppress this warning opt to use a controlled SwitchBase.

Only for it to give so I changed the checkbox to this.

<Checkbox value={row.name + "_checkbox"} defaultChecked />

Then it gave me some error about not having a key so I added a key to the checkbox

<Checkbox key={row.name + "_checkbox_key"} value={row.name + "_checkbox"} defaultChecked />

Now everything works the way I wanted it to work.

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!