add 0.5s delay before switching

This commit is contained in:
Sergey Krashevich 2023-07-07 14:28:25 +03:00
parent ca09f5d2d3
commit 186e6a4a34
No known key found for this signature in database
GPG Key ID: 625171324E7D3856

View File

@ -101,12 +101,19 @@ function Camera({ name, config }) {
); );
const [isHovered, setIsHovered] = useState(false); // Add a state to track if the mouse is over the card const [isHovered, setIsHovered] = useState(false); // Add a state to track if the mouse is over the card
const [timerId, setTimerId] = useState(null); // Add a state to keep track of the timer
const handleMouseEnter = () => { const handleMouseEnter = () => {
// Set a timer to change the state after 0.5 seconds
const id = setTimeout(() => {
setIsHovered(true); setIsHovered(true);
}, 500);
setTimerId(id);
}; };
const handleMouseLeave = () => { const handleMouseLeave = () => {
// Clear the timer if the mouse leaves before the 0.5 seconds are up
clearTimeout(timerId);
setIsHovered(false); setIsHovered(false);
}; };