UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

48 lines (46 loc) 1.46 kB
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_loading_provider = require('../../components/loading/loading-provider.cjs'); const require_hooks_use_processing_index = require('../use-processing/index.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); //#region src/hooks/use-async-callback/index.ts /** * `useAsyncCallback` is a custom hook used to manage async callbacks. * * @see https://yamada-ui.com/docs/hooks/use-async-callback */ const useAsyncCallback = (callback, deps, { loading: method = false, loadingOptions, processing: shouldProcessing = true } = {}) => { const context = require_loading_provider.useLoading(); const { finish, loading, start } = require_hooks_use_processing_index.useProcessing(); const shouldLoading = !!method; return [ loading, (0, react.useCallback)(async (...args) => { try { if (shouldProcessing) start(); if (shouldLoading) context[method].start(loadingOptions); return await callback(...args); } finally { if (shouldProcessing) finish(); if (shouldLoading) context[method].finish(); } }, [ ...deps, shouldProcessing, shouldLoading, context, method, loadingOptions, callback, start, finish ]), (0, react.useMemo)(() => ({ finish, start }), [finish, start]) ]; }; //#endregion exports.useAsyncCallback = useAsyncCallback; //# sourceMappingURL=index.cjs.map