Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.13 KB

README.md

File metadata and controls

51 lines (35 loc) · 1.13 KB

npm NPM

Package Name

Installation

npm install @flexcodelabs/use-events-hooks

or

yarn add @flexcodelabs/use-events-hooks

Usage

...
import { useEventListener, useWindowSize, useClickOutsideListener} from '@flexcodelabs/use-events-hooks';

const Test = () => {
  const buttonRef = useRef(null);

  // window size
  const { width, height } = useWindowSize();

  // event listener
  useEventListener("scroll", () => {
    console.log("scrolled");
  });

  // detect outside clicks
  useClickOutsideListener(buttonRef, () => {
    console.log("clicked outside");
  });

  return (
    <div>
      viewport size: {width}x{height}
      <button ref={buttonRef}>Text</button>
    </div>
  );
};

Examples

Source code