{"version":3,"sources":["../../src/use-layout-mount/index.ts"],"sourcesContent":["import { useRef } from 'react'\nimport { useLatest } from '../use-latest'\nimport { useLayoutEffectOnce } from '../use-layout-effect-once'\nimport { isFunction } from '../utils/basic'\n\nimport type { AnyFunc } from '../utils/basic'\n\n/**\n * A React Hooks that is similar to <Link to=\"/reference/use-mount\">`useMount`</Link> but use <Link to=\"/reference/use-isomorphic-layout-effect\">`useIsomorphicLayoutEffect`</Link> under the hood.\n *\n * Usually, you should use `useLayoutMount` instead of `useMount` if you want to run some code that may affect the layout in the next frame.\n *\n * `strictOnce` option is **NOT** recommended as it [damages](https://react.dev/learn/synchronizing-with-effects#dont-use-refs-to-prevent-effects-from-firing) the original intention of the **Strict Mode** of React 18.\n *\n * @param callback The callback to run when the component is mounted (useLayoutEffect).\n * @param strictOnce If `true`, the callback will only be executed once. NOTE: **NOT** recommended.\n * @returns {void} `void`\n *\n */\nexport function useLayoutMount(callback?: AnyFunc | null | undefined | false, strictOnce = false): void {\n  const isMountedOnceRef = useRef(false)\n  const latest = useLatest({ callback })\n\n  useLayoutEffectOnce(() => {\n    if (!latest.current) return\n\n    if (strictOnce) {\n      /**\n       * use `ref` to mark to prevent effect re-executed in the `strict mode` of React 18.\n       *\n       * @see https://react.dev/reference/react/StrictMode#fixing-bugs-found-by-re-running-effects-in-development\n       */\n      if (!isMountedOnceRef.current) {\n        isMountedOnceRef.current = true\n\n        if (isFunction(latest.current.callback)) {\n          latest.current.callback()\n        }\n      }\n    } else {\n      if (isFunction(latest.current.callback)) {\n        latest.current.callback()\n      }\n    }\n  })\n}\n"],"names":["useLayoutMount","callback","strictOnce","isMountedOnceRef","useRef","latest","useLatest","useLayoutEffectOnce","current","isFunction"],"mappings":";;;;+BAmBgBA;;;eAAAA;;;qBAnBO;yBACG;mCACU;qBACT;AAgBpB,SAASA,eAAeC,QAA6C;QAAEC,aAAAA,iEAAa;IACzF,IAAMC,mBAAmBC,IAAAA,aAAM,EAAC;IAChC,IAAMC,SAASC,IAAAA,oBAAS,EAAC;QAAEL,UAAAA;IAAS;IAEpCM,IAAAA,wCAAmB,EAAC;QAClB,IAAI,CAACF,OAAOG,OAAO,EAAE;QAErB,IAAIN,YAAY;YACd;;;;OAIC,GACD,IAAI,CAACC,iBAAiBK,OAAO,EAAE;gBAC7BL,iBAAiBK,OAAO,GAAG;gBAE3B,IAAIC,IAAAA,iBAAU,EAACJ,OAAOG,OAAO,CAACP,QAAQ,GAAG;oBACvCI,OAAOG,OAAO,CAACP,QAAQ;gBACzB;YACF;QACF,OAAO;YACL,IAAIQ,IAAAA,iBAAU,EAACJ,OAAOG,OAAO,CAACP,QAAQ,GAAG;gBACvCI,OAAOG,OAAO,CAACP,QAAQ;YACzB;QACF;IACF;AACF"}