Skip to content

Instantly share code, notes, and snippets.

View AliRazaviDeveloper's full-sized avatar
🎯
Focusing

AliRazavi AliRazaviDeveloper

🎯
Focusing
View GitHub Profile
@AliRazaviDeveloper
AliRazaviDeveloper / retryDynamicImport.ts
Last active October 25, 2024 15:56 — forked from mberneti/retryDynamicImport.ts
This utility function retryDynamicImport enhances React’s lazy loading mechanism by adding retry logic with a versioned query parameter. It retries importing a component multiple times in case of failure, which can be useful for bypassing browser cache or dealing with intermittent network issues. It can be used as a drop-in replacement for React…
import { ComponentType, lazy } from "react";
interface RetryOptions {
maxRetryCount?: number;
retryDelayMs?: number;
}
const DEFAULT_RETRY_OPTIONS: Required<RetryOptions> = {
maxRetryCount: 15,
retryDelayMs: 500,