JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19842
  • Score
    100M100P100Q137831F
  • License MIT

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

Package Exports

  • react-use-event-hook
  • react-use-event-hook/dist/cjs/useEvent.js
  • react-use-event-hook/dist/esm/useEvent.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-use-event-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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