Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-hook/event

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-hook/event

A React hook for managing event listeners, e.g. removing events when a component unmounts.

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
176K
decreased by-8.1%
Maintainers
1
Weekly downloads
 
Created

What is @react-hook/event?

@react-hook/event is a React hook library that provides utilities for handling events in a React application. It simplifies the process of adding and removing event listeners, making it easier to manage event-driven logic in functional components.

What are @react-hook/event's main functionalities?

useEvent

The `useEvent` hook allows you to create an event handler that is automatically memoized. This helps in preventing unnecessary re-renders and ensures that the event handler is stable across renders.

```javascript
import { useEvent } from '@react-hook/event';

function MyComponent() {
  const handleClick = useEvent((event) => {
    console.log('Button clicked!', event);
  });

  return <button onClick={handleClick}>Click me</button>;
}
```

useWindowEvent

The `useWindowEvent` hook allows you to add an event listener to the window object. This is useful for handling global events like window resize or scroll.

```javascript
import { useWindowEvent } from '@react-hook/event';

function MyComponent() {
  useWindowEvent('resize', () => {
    console.log('Window resized!');
  });

  return <div>Resize the window to see the effect.</div>;
}
```

useDocumentEvent

The `useDocumentEvent` hook allows you to add an event listener to the document object. This is useful for handling events that are not specific to a particular element, such as key presses.

```javascript
import { useDocumentEvent } from '@react-hook/event';

function MyComponent() {
  useDocumentEvent('keydown', (event) => {
    console.log('Key pressed:', event.key);
  });

  return <div>Press any key to see the effect.</div>;
}
```

Other packages similar to @react-hook/event

Keywords

FAQs

Package last updated on 10 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc