useWindowEvent
Add a typed window event listener that is removed on unmount.
Source@monoline/react 0.4.0Markdown for AI toolsstable
- No DOM output.
Import
import '@monoline/css';
import {useWindowEvent} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add use-window-event
Usage
import {useState} from 'react';
import {useWindowEvent, type Demo} from '@monoline/react';
function Demo() {
const [key, setKey] = useState('none');
useWindowEvent('keydown', (e) => setKey(e.key));
return <p>Last key pressed: <kbd className="kbd">{key}</kbd></p>;
}
<Demo />
Examples
Last key
Behaviour
- No DOM output.