I have a quite simple question. Can me someone tell, why the status of the checkboxes doesn't change? The booleans in check change, but not the status of the checkboxes.
function KP() {
const [name] = useState(["1", "2"]);
const [check, setCheck] = useState([true, false]);
const handleChange = (event) => {
const { id, checked } = event.target;
const index = name.indexOf(id);
var temp = check;
temp[index] = checked;
setCheck(temp);
};
return (
<div>
{name.map((n, index) => {
return (
<div>
<p>{n}</p>
<input type="checkbox" checked={check[index]} onChange={handleChange} id={n} key={n}/>
</div>
);
})}
</div>
);
}