@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 1.46 kB
Source Map (JSON)
{"version":3,"file":"index.cjs","names":["useBoolean"],"sources":["../../../../src/hooks/use-processing/index.ts"],"sourcesContent":["\"use client\"\n\nimport { useCallback, useMemo, useRef } from \"react\"\nimport { useUnmountEffect } from \"../../utils\"\nimport { useBoolean } from \"../use-boolean\"\n\n/**\n * `useProcessing` is a custom hook for handling processing states.\n *\n * @see https://yamada-ui.com/docs/hooks/use-processing\n */\nexport const useProcessing = (init?: boolean) => {\n const [loading, { off, on }] = useBoolean(init)\n const countRef = useRef<number>(0)\n\n const start = useCallback(() => {\n countRef.current += 1\n\n on()\n }, [on])\n\n const finish = useCallback(() => {\n countRef.current -= 1\n\n if (countRef.current <= 0) off()\n }, [off])\n\n useUnmountEffect(() => {\n countRef.current = 0\n })\n\n const controls = useMemo(\n () => ({\n finish,\n loading,\n start,\n }),\n [finish, loading, start],\n )\n\n return controls\n}\n\nexport type UseProcessingReturn = ReturnType<typeof useProcessing>\n"],"mappings":";;;;;;;;;;;;;;;AAWA,MAAa,iBAAiB,SAAmB;CAC/C,MAAM,CAAC,SAAS,EAAE,KAAK,QAAQA,2CAAW,KAAK;CAC/C,MAAM,6BAA0B,EAAE;CAElC,MAAM,qCAA0B;AAC9B,WAAS,WAAW;AAEpB,MAAI;IACH,CAAC,GAAG,CAAC;CAER,MAAM,sCAA2B;AAC/B,WAAS,WAAW;AAEpB,MAAI,SAAS,WAAW,EAAG,MAAK;IAC/B,CAAC,IAAI,CAAC;AAET,uCAAuB;AACrB,WAAS,UAAU;GACnB;AAWF,kCARS;EACL;EACA;EACA;EACD,GACD;EAAC;EAAQ;EAAS;EAAM,CACzB"}