UNPKG

tdesign-react

Version:
33 lines (29 loc) 1.08 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ import React from 'react'; import noop from '../_util/noop.js'; var useInsertionEffect = typeof window !== "undefined" ? React.useInsertionEffect || React.useLayoutEffect : noop; function useEventCallbackShouldNotBeInvokedBeforeMount() { throw new Error("INVALID_USEEVENTCALLBACK_INVOCATION: the callback from useEventCallback cannot be invoked before the component has mounted."); } function useEventCallback(callback) { var latestRef = React.useRef(useEventCallbackShouldNotBeInvokedBeforeMount); useInsertionEffect(function () { latestRef.current = callback; }, [callback]); var stableRef = React.useRef(null); if (!stableRef.current) { stableRef.current = function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return latestRef.current.apply(this, args); }; } return stableRef.current; } export { useEventCallback as default }; //# sourceMappingURL=useEventCallback.js.map