I have this component
const CheckboxColumn: FC<ICheckboxColumnProps> = ({ id_llamada }) => {
// select pickup
const dispatch = useTypedDispatch();
const [isPickupSelected, setIsPickupSelected] = useState(false);
const selectPickup = (e: ChangeEvent<HTMLInputElement>) => {
setIsPickupSelected(e.target.checked);
dispatch(controlPickup(id_llamada));
};
return (
<TableCell
component={'div'}
padding="checkbox"
sx={{ padding: '0px 0px 0px 4px' }}
onClick={(e) => {
e.stopPropagation();
}}
>
<Checkbox
color="primary"
checked={isPickupSelected ? true : false}
// disabled={true}
sx={{
padding: '7px',
'&:hover': {
backgroundColor: 'rgba(0, 0, 0, 0.06)',
},
}}
onChange={selectPickup}
/>
</TableCell>
);
};
export default CheckboxColumn;
And i need to be able to select a table's row, but also dispatch its information to redux, the problem, is that, i can't figure out how to use setState along with dispatch
What is currently happening, is that, my isPickupSelected is not updating its value, but data it's actually being saved in my reducer, and, when i comment the dispatch(function()) my state is being able to work properly.
I've been trying to search solutions to this, and one of them was that, i should use useEffect and whenever my state changes, i should dispatch the function, and it works, but immediately, it literally restarts my component, and also my isPickupSelected so my state is no longer updated but returns to its original value false
What am i supposed to do in this case