How can you achieve either a hover event or active event in ReactJS when you do inline styling?
I\'ve found that the onMouseEnter, onMouseLeave approach is buggy, so
The previous answers are pretty confusing. You don't need a react-state to solve this, nor any special external lib. It can be achieved with pure css/sass:
The style:
.hover {
position: relative;
&:hover &__no-hover {
opacity: 0;
}
&:hover &__hover {
opacity: 1;
}
&__hover {
position: absolute;
top: 0;
opacity: 0;
}
&__no-hover {
opacity: 1;
}
}
The React-Component
A simple Hover
Pure-Rendering-Function:
const Hover = ({ onHover, children }) => (
{children}
{onHover}
)
Usage
Then use it like this:
Show this on hover