Declarative React hook for eventListener
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.babelrc everything now Feb 6, 2019
.gitignore everything now Feb 6, 2019
LICENSE everything now Feb 6, 2019
README.md remove dependencies from readme Feb 7, 2019
dist.js release donavon's patch Feb 9, 2019
index.js a few fixes Feb 8, 2019
package.json release donavon's patch Feb 9, 2019
yarn.lock everything now Feb 6, 2019

README.md



Declarative React hook for eventListener

Demo on CodeSandbox

 

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>
}

Run on CodeSandbox

 

but why?

Long answer long: overreacted.io/making-setinterval-declarative-with-react-hooks/

like it?

⭐️ this repo

 

license

MIT © siddharthkp