{"version":3,"sources":["../../src/use-mount/index.ts"],"sourcesContent":["import { useRef } from 'react'\nimport { useEffectOnce } from '../use-effect-once'\nimport { useLatest } from '../use-latest'\nimport { isFunction } from '../utils/basic'\n\nimport type { AnyFunc } from '../utils/basic'\n\n/**\n * A React Hook that runs a function only once when the component mounts.\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.\n * @param strictOnce If `true`, the callback will only be executed once. NOTE: **NOT** recommended.\n * @returns {void} `void`\n *\n */\nexport function useMount(callback?: AnyFunc | null | undefined | false, strictOnce = false): void {\n  const isMountedOnceRef = useRef(false)\n  const latest = useLatest({ callback })\n\n  useEffectOnce(() => {\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":["useMount","callback","strictOnce","isMountedOnceRef","useRef","latest","useLatest","useEffectOnce","current","isFunction"],"mappings":";;;;+BAiBgBA;;;eAAAA;;;qBAjBO;6BACO;yBACJ;qBACC;AAcpB,SAASA,SAASC,QAA6C;QAAEC,aAAAA,iEAAa;IACnF,IAAMC,mBAAmBC,IAAAA,aAAM,EAAC;IAChC,IAAMC,SAASC,IAAAA,oBAAS,EAAC;QAAEL,UAAAA;IAAS;IAEpCM,IAAAA,4BAAa,EAAC;QACZ,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"}