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

139
Views
Why changes in Checkbox's value are not displayed?

I'm using react and material ui. I need to get all checkboxes in a list checked by checking one checkbox in a parent component (i.e. I need to select all). I pass down the correct value of the parent checkbox via props, but that doesn't trigger visual changes in its children, even though their values do change to 'true'. I'm sure that the values are correct, because I tried logging them to the console.

Here's the parent:

const [checkboxValue, setCheckboxValue] = useState(false)

<Checkbox value={checkboxValue} onChange={e => setCheckboxValue(e.target.checked)}/>
{elements.map(element => (<Element selectAll={checkboxValue}/>))}

And here's the child:

function Element(props) {
    const [checkboxValue, setCheckboxValue] = useState(false)
    useEffect(() => {
        setCheckboxValue(props.selectAll)
    }, [props.selectAll])

return (
<Checkbox value={checkboxValue} onChange={e => setCheckboxValue(e.target.checked)}/>)
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you are using value instead of checked

function SingleCheckBox({ selectAll }) {
  const [checkboxValue, setCheckboxValue] = useState(selectAll);

  useEffect(() => {
    setCheckboxValue(selectAll);
  }, [selectAll]);

  return (
    <Checkbox
      checked={checkboxValue}
      onChange={(e) => setCheckboxValue(e.target.checked)}
    />
  );
}

export default function App() {
  const [checkboxValue, setCheckboxValue] = useState(false);

  return (
    <div className="App">
      <Checkbox
        checked={checkboxValue}
        onChange={(e) => {
          setCheckboxValue(e.target.checked);
        }}
      />
      <div>
        <h2>Other checkboxes</h2>
        <SingleCheckBox selectAll={checkboxValue} />
      </div>
    </div>
  );
}

https://codesandbox.io/s/angry-buck-yp7f3z?file=/src/App.js

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!