So, I am getting a list of data from the backend
const [data, setData] = useState([]);
const getDataSet = async () => {
const { data } = await inapp.get('/v1/vcr/getData');
setData(data.payload);
useEffect(() => {
getData();
}, []);
I am rendering a list of checkboxes using the array map function Then, I have a button
const [checked, setChecked] = useState([]);
const handleToggle = (value) => {
const currentIndex = checked.indexOf(value);
const newChecked = [...checked];
if (currentIndex === -1) {
newChecked.push(value);
} else {
newChecked.splice(currentIndex, 1);
}
setChecked(newChecked);
};
const renderDataCheckboxes = () => {
return (
<div className={classes.inlineChecks}>
{data.map((row) => {
return (
<FormControlLabel
key={row.id}
control={
<Checkbox
tabIndex={-1}
onClick={() => handleToggle(row.name)}
checked={checked.indexOf(row.name) !== -1}
checkedIcon={<Check className={classes.checkedIcon} />}
icon={<Check className={classes.uncheckedIcon} />}
classes={{
checked: classes.checked,
root: classes.checkRoot,
}}
/>
}
classes={{ label: classes.label }}
label={row.name}
/>
);
})}
</div>
);
};
I also have a button that will remove the checked items from the backend. Question is, how do I cause the checkboxes to re-render to remove the deleted items?