use-event-listener
v1.0.4
Published
Declarative React hook for eventListener
Downloads
330
Readme
install
npm install use-event-listener
usage
import useEventListener from 'use-event-listener'
function Example() {
const [key, setKey] = useState()
useEventListener(
'keydown', // event to listen to
event => setKey(event.key) // callback
)
return <div>{key} was pressed</div>
}
but why?
Long answer long: overreacted.io/making-setinterval-declarative-with-react-hooks/
like it?
:star: this repo
license
MIT © siddharthkp