npm.io
1.3.0 • Published 4 years ago

@react-hookbox/event-callback

Licence
MIT
Version
1.3.0
Deps
0
Size
12 kB
Vulns
0
Weekly
0

@react-hookbox/event-callback

Material UI's useEventCallback with better type definitions.

NPM Minzipped Bundle Size

Install

npm install --save @react-hookbox/event-callback

or

yarn add @react-hookbox/event-callback

Usage

both for JavaScript and Typescript:

import { useEventCallback } from '@react-hookbox/event-callback';
// OR
// import useEventCallback from '@react-hookbox/event-callback';

// then
const myCallback = useEventCallback((num, str) => {
  return str.repeat(Math.min(num, 2));
});

useEventCallback updates the callback it's using after an "effective-time". So make sure to use it as a callback or in a useEffect which is placed after useEventCallback;

Params

  • fn. This is a required function parameter. The returned value will have the same type.

    Note: The return value will be updated after an "effect-ive time".

    That means the returned value should be used as an event callback or in an event callback.

License

MIT hakobpogh

Keywords