'How to handle multiple checkboxes in React?

I am new to react. I have got a task to:

  • Display multiple checkboxes.
  • Checkboxes names can be shuffled in the future. (Client can decide which checkbox value to be displayed at the top and so on).
  • Display checkboxes based on order no.
  • There will be a submit button below the checkbox which will be disabled on load. Force the user to tick all the check boxes only then the button should be enabled.
  • On click of save button, send the data to backend. (For the time being I will log to console).

I am using react with typescript.
I have attached a snapshot for reference. Multiple checboxes example
So far I have done this:

import React, { useState } from "react";

interface Data {
  name: string;
  order: number;
}

const MyCheckBoxList: Data[] = [
  {
    order: 0,
    name: "Angular",
  },
  {
    order: 1,
    name: "React",
  },
  {
    order: 2,
    name: "Java",
  },
];

const MultipleCheckBoxComponent = () => {
  const [checked, setChecked] = useState(false);

  return (
    <div>
      <h3>Multiple checbox </h3> <br />
      <ul>
        {MyCheckBoxList.map(({ name, order }, index) => {
          return (
            <li key={index}>
              <div>
                <div>
                  <input
                    type="checkbox"
                    id={`custom-checkbox-${index}`}
                    name={name}
                    value={name}
                  />
                </div>
              </div>
            </li>
          );
        })}
      </ul>
      <button type="submit">Save</button>
    </div>
  );
};

export default MultipleCheckBoxComponent;

Can anybody tell me:
How do I display the check boxes based on order number (as I have mentioned in point 3) and how to achieve point 4?(the button should enable only when all the checkboxes are tick)


Solution 1:[1]

Thanks to @jay.sf I was able to find a solution. I included the maxsum= argument as seen below (NB: I used 12 because that's the number of levels of the variable):

pam_fit <- pam(gower_dist, diss = TRUE, k)
pam_results <- df.torun %>% 
  mutate(cluster = pam_fit$clustering) %>% 
  group_by(cluster) %>% 
  do(the_summary = summary(., maxsum = 12))
pam_results$the_summary

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VFdezM