@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 1.81 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["timeoutId: NodeJS.Timeout | null"],"sources":["../../../../src/hooks/use-mounted/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useRef, useState } from \"react\"\nimport { useSafeLayoutEffect } from \"../../utils\"\n\nexport interface UseMountedProps {\n delay?: number\n state?: boolean\n}\n\nexport function useMounted(props?: {\n delay?: number\n state?: false\n}): () => boolean\n\nexport function useMounted(props?: { delay?: number; state?: true }): boolean\n\nexport function useMounted({ delay = 0, state = false }: UseMountedProps = {}) {\n const mountedRef = useRef(false)\n const [mounted, setMounted] = useState(false)\n\n useSafeLayoutEffect(() => {\n mountedRef.current = true\n\n let timeoutId: NodeJS.Timeout | null = null\n\n if (state) {\n if (delay > 0) {\n timeoutId = setTimeout(() => setMounted(true), delay)\n } else {\n setMounted(true)\n }\n }\n\n return () => {\n mountedRef.current = false\n\n if (state) setMounted(false)\n\n if (timeoutId) clearTimeout(timeoutId)\n }\n }, [delay, state])\n\n if (state) {\n return mounted\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useCallback(() => mountedRef.current, [])\n }\n}\n\nexport type UseMountedReturn = ReturnType<typeof useMounted>\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,WAAW,EAAE,QAAQ,GAAG,QAAQ,UAA2B,EAAE,EAAE;CAC7E,MAAM,+BAAoB,MAAM;CAChC,MAAM,CAAC,SAAS,kCAAuB,MAAM;AAE7C,0CAA0B;AACxB,aAAW,UAAU;EAErB,IAAIA,YAAmC;AAEvC,MAAI,MACF,KAAI,QAAQ,EACV,aAAY,iBAAiB,WAAW,KAAK,EAAE,MAAM;MAErD,YAAW,KAAK;AAIpB,eAAa;AACX,cAAW,UAAU;AAErB,OAAI,MAAO,YAAW,MAAM;AAE5B,OAAI,UAAW,cAAa,UAAU;;IAEvC,CAAC,OAAO,MAAM,CAAC;AAElB,KAAI,MACF,QAAO;KAGP,qCAAyB,WAAW,SAAS,EAAE,CAAC"}