I have multiple checkbox svgs which i'm mapping over which removes the inner tick icon when I manually set either of the isSelected states to false. I want to remove/add the tick icon svg when I press the checkbox in my app. Im unsure where Im currently going wrong in my logic. It works correctly when I manually change the isSelected state to false but not when I press the checkbox.
State:
const [option, setOption] = useState([
{ permission: 'Can manage users', isSelected: true },
{ permission: 'Can place orders', isSelected: true },
]);
Component:
{option.map(({ permission, isSelected }, i) => (
<CheckboxIcon
viewed={isSelected}
onPress={() =>
setOption(prev => {
prev[i] = { ...prev[i], isSelected: !isSelected };
return prev;
})
}
/>
Checkbox svg:
const CheckboxIcon = ({
width = 26,
height = 26,
viewed,
fill = Colors.success,
tickAccountSize,
onPress,
}) => (
<Svg
xmlns="http://www.w3.org/2000/svg"
overflow="visible"
preserveAspectRatio="none"
width={width}
height={height}>
<Path
d="M1 1h24v24H1V1z"
vectorEffect="non-scaling-stroke"
fill="transparent"
/>
<IconContainer onPress={onPress} width={width} height={height}>
{viewed && <TickIcon tickAccountSize fill={fill} />}
</IconContainer>
</Svg>
);