UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

27 lines (26 loc) 583 B
import { c } from "react-compiler-runtime"; import { useEffect, useRef } from "react"; //#region src/internal/hooks/useEffectOnce.ts function useEffectOnce(callback) { const $ = c(2); const savedCallback = useRef(callback); const called = useRef(false); let t0; let t1; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t0 = () => { if (called.current === true) return; called.current = true; savedCallback.current(); }; t1 = []; $[0] = t0; $[1] = t1; } else { t0 = $[0]; t1 = $[1]; } useEffect(t0, t1); } //#endregion export { useEffectOnce };