useEventListener
Add and remove event listeners on the targeted object.
Usage
useEventListener
adds an EventListener to the passed event
and call the listener
callback when triggered, once the component is destroyed it removes the EventListener.
EventListener options can be passed through options
.
import { useEventListener } from "swash/utils/useEventListener";
function Example({ skip }) {
const [key, setKey] = useState();
useEventListener(document, "keyup", (event) => {
setKey(event.key);
});
return <div>{key}</div>;
}