@jdthornton/useeventlistener
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@jdthornton/useeventlistener

npm (scoped) npm bundle size (minified)

React event listener hook.

Install

$ npm install @jdthornton/useeventlistener

Usage

import useEventListener from "@jdthornton/useeventlistener";

function App({
  isListening,
  el = window
}){

  const handleScroll = (e) => {
    console.log("window scroll event", e)
  };

  // Listens to the window scroll event if isListening is true
  useEventListener(
    isListening ? "scroll" : null,
    handleScroll,
    el
  )

  return null
}

Readme

Keywords

none

Package Sidebar

Install

npm i @jdthornton/useeventlistener

Weekly Downloads

10

Version

1.0.5

License

ISC

Unpacked Size

3.86 kB

Total Files

5

Last publish

Collaborators

  • jdthornton