The type of the React component being loaded.
A function returning a promise that resolves to the dynamically imported React component.
Optional
retries: number = 5The number of retry attempts if loading fails. Defaults to 5.
Optional
interval: number = 1000The delay in milliseconds between retry attempts. Defaults to 1000 ms.
A lazily loaded React component with retry logic.
// Example usage with a dynamic import:
const LazyComponent = lazyRetry(() => import('./MyComponent'));
// Optionally with custom retry settings:
const LazyComponentWithRetries = lazyRetry(() => import('./MyComponent'), 3, 2000);
// Inside your JSX:
<Suspense fallback={<div>Loading...</div>}>
<LazyComponent />
</Suspense>
Lazily loads a React component with automatic retry logic. This function wraps React's
lazy
function to allow retrying a component load in case of failure, with configurable retry attempts and intervals.The retry mechanism is useful for dynamic imports where loading may fail due to network issues or other reasons, allowing for a better user experience through automated retries before giving up.