Documentacion/API/Recovery / reintentos

Recovery / reintentos

Politica de reintentos con delay/backoff.

Recovery / reintentos (recovery)

recovery es opcional. Si lo provees, resetError() aplica una politica de reintentos:

  • maxRetries: maximo numero de intentos.
  • retryDelay: delay antes de resetear. Puede ser:
    • number: delay fijo.
    • function(attempt, error): delay dinamico.
  • isRecoverable: si retorna false, resetError() hace reset inmediato (no cuenta como retry).
  • onMaxRetriesReached: se llama cuando se supera el maximo; en ese caso NO se resetea (te quedas en fallback).

Ejemplo con backoff simple

1import { ErrorBoundary } from "react-rescuer";
2
3export function Demo() {
4 return (
5 <ErrorBoundary
6 recovery={{
7 maxRetries: 3,
8 retryDelay: (attempt) => Math.min(1000, 200 * 2 ** (attempt - 1)),
9 }}
10 fallbackRender={({ error, resetError, retryCount }) => (
11 <div>
12 <div>{error.message}</div>
13 <div>retryCount: {retryCount}</div>
14 <button onClick={resetError}>Retry</button>
15 </div>
16 )}
17 >
18 <Page />
19 </ErrorBoundary>
20 );
21}
COPIAR

Como se interpreta retryCount

  • Empieza en 0.
  • Se incrementa cuando resetError() inicia un retry permitido.
  • Se resetea a 0 cuando el reset es imperative o por resetKeys.
Max retries

Si superas maxRetries, el boundary se queda en el fallback y se dispara onMaxRetriesReached.