@flexcodelabs/use-events-hooks
v0.1.0
Published
[![npm](https://img.shields.io/npm/v/@flexcodelabs/use-events-hooks)](https://www.npmjs.com/package/@flexcodelabs/use-events-hooks) [![NPM](https://img.shields.io/npm/l/@flexcodelabs/use-events-hooks)](https://www.npmjs.com/package/@flexcodelabs/use-event
Downloads
1
Readme
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>
);
};