1.0.5 • Published 2 years ago

@jdthornton/useeventlistener v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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