@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
30 lines (28 loc) • 979 B
JavaScript
import * as React from "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
export { useSafeLayoutEffect, useUnmountEffect, useUpdateEffect };
//# sourceMappingURL=effect.js.map