Package Exports
- @react-hookbox/enhanced-callback
- @react-hookbox/enhanced-callback/dist/index.js
- @react-hookbox/enhanced-callback/dist/index.modern.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-hookbox/enhanced-callback) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@react-hookbox/enhanced-callback
The enhanced version of useCallback. Enhanced callback doesn't need deps array and keeps reference the same.
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