@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
34 lines (32 loc) • 1.18 kB
JavaScript
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let react = require("react");
react = require_rolldown_runtime.__toESM(react);
//#region src/utils/effect.ts
const useSafeLayoutEffect = Boolean(globalThis.document) ? react.useLayoutEffect : react.useEffect;
function useUnmountEffect(callback) {
return react.useEffect(() => () => callback(), []);
}
/**
* `useUpdateEffect` is a custom hook that skips side effects on the initial render, and only runs them when the dependency array changes.
*
* @see https://yamada-ui.com/docs/hooks/use-update-effect
*/
function useUpdateEffect(callback, deps) {
const renderCycleRef = react.useRef(false);
const effectCycleRef = react.useRef(false);
react.useEffect(() => {
if (renderCycleRef.current && effectCycleRef.current) return callback();
effectCycleRef.current = true;
}, deps);
react.useEffect(() => {
renderCycleRef.current = true;
return () => {
renderCycleRef.current = false;
};
}, []);
}
//#endregion
exports.useSafeLayoutEffect = useSafeLayoutEffect;
exports.useUnmountEffect = useUnmountEffect;
exports.useUpdateEffect = useUpdateEffect;
//# sourceMappingURL=effect.cjs.map