3.2.4 • Published 10 months ago
@piplup/use-event-listener v3.2.4
@piplup/use-event-listener
⚠️ Deprecation Warning
Important Notice:
useEventListenerhook has been moved to @piplup/utils, While it may continue to work for existing projects, we recommend migrating to the new package.
useEventListener is a custom React hook designed to simplify the process of adding event listeners to various DOM elements in React applications.
Installation
You can install useEventListener via npm or yarn:
npm install @piplup/use-event-listener
# or
yarn add @piplup/use-event-listener
# or
pnpm add @piplup/use-event-listenerUsage
'use client';
import * as React from 'react';
import { useEventListener } from '@piplup/use-event-listener';
function App() {
const handleResize = (event) => {
console.log('Window has been resized!', event);
};
useEventListener('resize', handleResize);
return <div>useEventListener Demo</div>;
}API
useEventListener(eventName, handler, element, options)
eventName(string): The name of the event to listen for, such as'click','resize', etc.handler(function): The event handler function that will be called when the event is triggered.element(RefObject): A React ref object referencing the DOM element to which the event listener will be attached. If not provided, the event listener will be attached to thewindowobject.options(AddEventListenerOptions | boolean, optional): Additional options to pass to theaddEventListenerfunction.
License
This project is licensed under the MIT License - see the LICENSE file for details.
3.2.2
1 year ago
3.2.1
1 year ago
3.1.2
1 year ago
3.2.0
1 year ago
3.1.1
1 year ago
3.1.0
1 year ago
3.2.4
10 months ago
3.2.3
10 months ago
3.0.0
1 year ago
2.8.1
1 year ago
2.7.0
1 year ago
2.8.0
1 year ago
1.5.1
1 year ago
1.5.0
1 year ago
1.4.0
1 year ago
1.3.0
1 year ago
1.2.0
1 year ago
1.1.1
1 year ago
1.1.0
2 years ago
1.0.0
2 years ago