I have a hover state that changes div background color and adds a <p> tag to a mapped component:
const [isHover, setIsHover] = useState(false)
Here is the mapped component where I set the state:
const AddSectionButton = ({
isHover,
setIsHover,
sections,
setSections,
nextSectionId,
setNextSectionId,
sectionTitle,
setSectionTitle,
sectionId,
}) => {
return (
<AddSectionDiv
onMouseEnter={() => {
setIsHover(!isHover);
}}
onMouseLeave={() => {
setIsHover(!isHover);
}}
style={isHover && { backgroundColor: "#A4AAE0" }}
>
{isHover && <p>Add Section</p>}
</AddSectionDiv>
);
};
Whenever I hover to a single mapped component, the rest of the mapped components trigger the hover effect as well.
How do I set the state to only the hovered component and not affect the rest?
I thought about using a key, where as you can see in my mapped component, I passed a sectionId prop which contains the key, but I'm confused as to how I should use it.