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

160
Views
Adding a select all, uncheck all function to my filter checkboxes react+typescript

I created this function which is a filter with checkboxes. How can I add the functionality where you can check all/uncheck all to my existing code, aslo adding typescript to it?

Any help is very appreciated!

function FilterCheckbox(props) {
  const wells = ["All","Legacy Wells", "Injection Wells", "Monitoring Wells"];
  const [checkedWells, setCheckedWells] = useState([]);

  const wellsProps = { wells, checkedWells, setCheckedWells };
  return (
    <div>
      <CheckedWells {...wellsProps} />
    </div>
  );
}

function CheckedWells(props) {
  const handleChecked = e => {
    const well = props.wells[e.target.dataset.id];
    let newCheckedWells = props.checkedWells.filter(item => item !== well);
    if (e.target.checked) newCheckedWells.push(well);
    props.setCheckedWells(newCheckedWells);
  };

  return (
    <div>
      {props.wells.map((well, id) => (
        <label key={id}>
          <input type="checkbox" data-id={id} onClick={handleChecked} /> {well}
        </label>
      ))}

      <p>{props.checkedValues}</p>
    </div>
  );
}
export default FilterCheckbox
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should add checkedattribute and handle your logic there. For example checked={props.checkedWells.includes(<your logic here>)

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!