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);
const { width, height } = useWindowSize();
useEventListener("scroll", () => {
console.log("scrolled");
});
useClickOutsideListener(buttonRef, () => {
console.log("clicked outside");
});
return (
<div>
viewport size: {width}x{height}
<button ref={buttonRef}>Text</button>
</div>
);
};
Examples
Source code