-
The documentation suggests overriding the I suggest exposing the import type { AppProps } from "next/app";
import { defaultSWRConfig, SWRConfig } from "swr";
import { ResponseError } from "@/errors/ResponseError";
export default function MyApp({ Component, pageProps }: AppProps) {
return (
<SWRConfig
value={{
onErrorRetry: (err, ...restArgs) => {
if (
err instanceof ResponseError &&
err.response.status >= 400 &&
err.response.status < 500
) {
return;
}
defaultSWRConfig.onErrorRetry(err, ...restArgs);
},
}}
>
<Component {...pageProps} />
</SWRConfig>
);
} For comparison, here’s the current method for achieving the same results: import type { AppProps } from "next/app";
import { SWRConfig } from "swr";
import { ResponseError } from "@/errors/ResponseError";
export default function MyApp({ Component, pageProps }: AppProps) {
return (
<SWRConfig
value={{
onErrorRetry: (err, _key, config, revalidate, revalidateOpts) => {
if (
err instanceof ResponseError &&
err.response.status >= 400 &&
err.response.status < 500
) {
return;
}
/* Base implementation adopted from SWR follows */
const maxRetryCount = config.errorRetryCount;
const currentRetryCount = revalidateOpts.retryCount;
// Exponential backoff
const timeout =
Math.trunc(
(Math.random() + 0.5) * 2 ** Math.min(currentRetryCount, 8),
) * config.errorRetryInterval;
if (maxRetryCount != null && currentRetryCount > maxRetryCount) {
return;
}
setTimeout(() => {
revalidate(revalidateOpts);
}, timeout);
},
}}
>
<Component {...pageProps} />
</SWRConfig>
);
} I think exposing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @kripod! It’s already exported here: Line 504 in 72a5480 |
Beta Was this translation helpful? Give feedback.
Hey @kripod!
It’s already exported here:
swr/src/use-swr.ts
Line 504 in 72a5480