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

react-use-event-hook

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-event-hook

Same as React's `useCallback`, but returns a stable reference.

  • 0.9.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by2.4%
Maintainers
1
Weekly downloads
 
Created
Source

react-use-event-hook

Same as React's useCallback, but returns a stable reference.

This library is a user-land implementation of the useEvent hook, proposed in this RFC.

Installation

npm install react-use-event-hook

Usage

(this example was copied from the RFC)

You can wrap any event handler into useEvent.

import useEvent from 'react-use-event-hook';

function Chat() {
  const [text, setText] = useState('');

  const onClick = useEvent(() => {
    sendMessage(text);
  });

  return <SendButton onClick={onClick} />;
}

The code inside useEvent “sees” the props/state values at the time of the call. The returned function has a stable identity even if the props/state it references change. There is no dependency array.

See more

Keywords

FAQs

Package last updated on 22 Mar 2023

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