@preact-signals/query
Version:
A reactive utility for React/Preact that simplifies the handling of data fetching and state management. Powered by Preact Signals, it provides hooks and functions to create reactive resources and manage their state seamlessly.
30 lines • 1.2 kB
JavaScript
"use client";
import { useSignalEffectOnce, useSignalOfReactive, } from "@preact-signals/utils/hooks";
import * as React from "react";
import { shouldThrowError } from "./utils.js";
export const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
if (options.suspense || options.useErrorBoundary) {
// Prevent retrying failed query if the error boundary has not been reset yet
if (!errorResetBoundary.isReset()) {
options.retryOnMount = false;
}
}
};
export const useClearResetErrorBoundary = (errorResetBoundary) => {
React.useEffect(() => {
errorResetBoundary.clearReset();
}, [errorResetBoundary]);
};
export const useClearResetErrorBoundary$ = (errorResetBoundary) => {
const $boundary = useSignalOfReactive(errorResetBoundary);
useSignalEffectOnce(() => {
$boundary.value.clearReset();
});
};
export const getHasError = ({ result, errorResetBoundary, useErrorBoundary, query, }) => {
return (result.isError &&
!errorResetBoundary.isReset() &&
!result.isFetching &&
shouldThrowError(useErrorBoundary, [result.error, query]));
};
//# sourceMappingURL=errorBoundaryUtils.js.map