I'm a newbie to React. I'm trying to update the like or bookmark count to 0 and 1 upon button click. When I click on the bookmark icon, both the icons gets toggled. The behavior seems inconsistent.
ToggleIcon Component
const ToggleIcon = ({ icon, color, styledIcon, handleClick }: any) => {
return (
<IonIcon icon={color ? styledIcon : icon} onClick={handleClick}></IonIcon>
);
};
Root Component
{config.map((props, index) => (
<ToggleIcon
style={{ padding: "10px" }}
handleClick={() => {
setColor(!color);
if (props.type === "bookmark") {
!color && props.type === "bookmark"
? setBookmarkCount(bookmarkCount + 1)
: setBookmarkCount(bookmarkCount - 1);
}
if (props.type === "like") {
!color && props.type === "like"
? setLikeCount(likeCount + 1)
: setLikeCount(likeCount - 1);
}
}}
color={color}
{...props}
/>
))}
I created a working example using CodeSandbox. Could anyone please help?