Outlook_Addin_LLM/node_modules/@fluentui/react-hooks/lib-amd/useConstCallback.js

25 lines
1.2 KiB
JavaScript
Raw Normal View History

define(["require", "exports", "react"], function (require, exports, React) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useConstCallback = void 0;
/**
* @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