There is an icon which says call is active, with classname "callConnect". When I hover on the icon, the icon should change, the new icon would be of classname "callDisconnect"
I am just writing a snippet to show my implementation which is not working:
I am using useRef and a functionto update
const hover = useRef(false)
const updateHoverState = (val: boolean) => {
hover.current = val
}
In my component i have a method which renders the icon as so:
<div onMouseOver={() => {
updateHoverState(true)
console.log("hovering", hover.current)}
}
onMouseOut={() => {
updateHoverState(false)
console.log("coming out", hover.current)}
}
>
{console.log("rendering", hover.current)} //not working
{hover.current ? <Icon onClick={() => { }} className={"callDisconnect"} /> :
<Icon onClick={() => { }} className={"callConnect"} />}
</div>
When i run the code, the I see that hover is getting updated to true and false properly when I hover and move out, but the icons are not changing. Re-rendering is not happening. How to fix please help.
Please note: I have already tried using useState, since it did not work, I switched to useRef.
useState:
const [hover, setHover] = useState(false)
<div onMouseOver={() => {
setHover(true)
}
onMouseOut={() => {
setHover(false)
}
>
{hover ? <Icon onClick={() => { }} className={"callDisconnect"} /> :
<Icon onClick={() => { }} className={"callConnect"} />} //not updating on hover
</div>