I have a checkbox element within a tab using MUI. When switching tabs it removes the checkbox visual.
{listItem.map((checkbox, index) => {
return (
<FormControlLabel className="twocolelement"
control={
<Checkbox
key={(index) + (checkbox.Name)}
name={checkbox.Name}
value={checkbox.Weight}
id={checkbox.Category}
checked={isChecked==index}
color="primary"
onChange={event => handleCheckboxChange(index, event)}
onClick={() => isCheckboxChecked(index)}
/>
}
label={(checkbox.Brand) + ' ' + (checkbox.Name)}
/>
);
})}
const [isChecked, setIsChecked] = React.useState([]);
const isCheckboxChecked = (index) => {
setIsChecked(index)
console.log(index)
}
This keeps the state but it works like a radio button (only allowing one selection)
How do I keep the checkbox state (checked) when moving between tabs?