UNPKG

@tanstack/react-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in React

32 lines (28 loc) 1.39 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const ensureStaleTime = defaultedOptions => { if (defaultedOptions.suspense) { // Always set stale time when using suspense to prevent // fetching again when directly mounting after suspending if (typeof defaultedOptions.staleTime !== 'number') { defaultedOptions.staleTime = 1000; } } }; const willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring; const shouldSuspend = (defaultedOptions, result, isRestoring) => (defaultedOptions == null ? void 0 : defaultedOptions.suspense) && willFetch(result, isRestoring); const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({ data }) => { defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data); defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null); }).catch(error => { errorResetBoundary.clearReset(); defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error); defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error); }); exports.ensureStaleTime = ensureStaleTime; exports.fetchOptimistic = fetchOptimistic; exports.shouldSuspend = shouldSuspend; exports.willFetch = willFetch; //# sourceMappingURL=suspense.js.map