I have a counter functional component, with 2 buttons: increment
and decrement
and currently, when they're clicked, the state changes. But I want the state to change as long as the mouse is over the element. (not like onMouseOver
that executes the event if the mouse is over, and then again when you move the mouse out from the element and then hover on the element again). I want it to be a constant hover event.
Heres my counter
code:
import React, { useState } from "react";
import "./styles.css";
export default function App() {
const [counter, setCounter] = useState(0)
return (
<div className="App">
<h1>{counter}</h1>
<button onClick={() => setCounter(counter + 1)}>Increment</button>
<button onClick={() => setCounter(counter - 1)} disabled={counter < 1 ? true : false}>Decrement</button>
</div>
);
}
I hope that makes sense! Thanks in advance.