@react-hookbox/enhanced-callback
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

@react-hookbox/enhanced-callback

The enhanced version of useCallback. Enhanced callback doesn't need deps array and keeps reference the same.

NPM Minzipped Bundle Size

Install

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

or

yarn add @react-hookbox/enhanced-callback

Usage

both for JavaScript and Typescript:

import { useEnhancedCallback } from '@react-hookbox/enhanced-callback';
// OR
// import useEnhancedCallback from '@react-hookbox/enhanced-callback';

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

// this will work everywherre in you code
myCallback(8, 'hello');

useEnhancedCallback updates the callback immediately so you can use it anytime you want. Just keep in mind that you should not rely on it to trigger update in any deps list as it returns the same function-reference and never changes it.

Params

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

License

MIT © hakobpogh

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.2
    17
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.2
    17
  • 1.1.1
    0
  • 1.1.0
    0
  • 1.0.0
    2

Package Sidebar

Install

npm i @react-hookbox/enhanced-callback

Weekly Downloads

19

Version

1.1.2

License

MIT

Unpacked Size

11.4 kB

Total Files

16

Last publish

Collaborators

  • hakobpogh