// utility hook
function useMouseOver() {
const [mouseOver, setMouseOver] = useState(false);
return {
mouseOver,
triggers: {
onMouseEnter: () => setMouseOver(true),
onMouseLeave: () => setMouseOver(false),
},
};
}
// mark component
function CommentHighlight({ attributes, children, ...props }) {
const { mouseOver, triggers } = useMouseOver();
return (
<span
{...attributes}
{...triggers}
style={{
background: mouseOver ? yellow[600] : yellow[200],
cursor: 'pointer',
}}
>
{children}
</span>
);
}
Imagine 2 overlapped comments, they have different marks but rendered with the same component CommentHighlight
:
-----
---------
aaaccbbbbbbb
a
- has the mark from comment 1b
- has the mark from comment 2c
- has marks from comments 1 and 2
When I hover over aaa
I need cc
to change color too. But how?
The only guess I have is to track highlight state in redux (or similar) and update every comment component on state change. But this looks like overkill.