UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

28 lines (24 loc) 601 B
/** * MSKCC 2021, 2024 */ import { useRef, useEffect } from 'react'; /** * A custom hook which will call the given callback exactly once when your * component is initially rendered and effects are first called * * @param {Function} callback */ function useEffectOnce(callback) { const savedCallback = useRef(callback); const effectGuard = useRef(false); useEffect(() => { savedCallback.current = callback; }); useEffect(() => { if (effectGuard.current !== true) { effectGuard.current = true; savedCallback.current(); } }, []); } export { useEffectOnce };