Here is my Solution for the Functional Based Components. I'm assuming that you're looking to change the colour of the button on the "mouse hover" event. You can use anything by following my code though.
Please import useState and useEffect hook as
import React, { useState, useEffect } from 'react';
Now, Make the state as:-
const [hover, setHover] = useState(false);
Define the colour that you want to render on Mouse Hover, I'm defining primary colour and mouseOverColor here.
let primaryColor:red
let mouseOverColor:blue
Now in JSX of Reactjs.
return (<div>
<Button
style={backGroundColor: hover === true ? mouseOverColor : primaryColor}
onMouseOver={(e) => {
e.preventDefault();
setHover(true);
}}
onMouseLeave={(e) => {
e.preventDefault();
setHover(false);
}}
>
Say hi
</Button>
</div>)
Please make sure to use useEffect dependency with the "hover" property so it should refresh background colour whenever the component gets mouseover effect as:-
useEffect(() => {}, [hover]);
Note:- I use button of Material UI, you can use plain HTML button too.
import { Button } from '@material-ui/core';
RESULT:- Norammly button would be Red and on Mouse Hover, it should be red and vice versa.
That's pretty much it.