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.
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)