24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.useConstCallback = void 0;
|
||
|
var React = require("react");
|
||
|
/**
|
||
|
* @deprecated Deprecated due to potential for misuse. Generally, use `React.useCallback` instead.
|
||
|
* If you need a callback reference that never changes, consider `useEventCallback`.
|
||
|
*
|
||
|
* This hook was intended for creating callbacks which have no dependencies, and therefore never
|
||
|
* need to change. It works fine if everyone using it is extremely mindful of how closures work,
|
||
|
* but that's not a safe assumption--so in practice, usage of this hook tends to result in bugs
|
||
|
* like unintentionally capturing the first value of a prop and not respecting updates (when
|
||
|
* updates should be respected).
|
||
|
*/
|
||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||
|
function useConstCallback(callback) {
|
||
|
var ref = React.useRef();
|
||
|
if (!ref.current) {
|
||
|
ref.current = callback;
|
||
|
}
|
||
|
return ref.current;
|
||
|
}
|
||
|
exports.useConstCallback = useConstCallback;
|
||
|
//# sourceMappingURL=useConstCallback.js.map
|