A simple and safe way to use React.lazy
when you are iterating React app fast. It will catch the error and automatically retry to import or refresh the page when a lazy React component fails to load.
Installation
npm i react-safe-lazy
- Direct dependencies: 0.
- Peer dependency:
react@^18.0.0
.
Usage
Just replace React.lazy
with safeLazy
and you are good to go.
import { safeLazy } from 'react-safe-lazy';
const MyComponent = safeLazy(() => import('./MyComponent'));
Note
Please check README for more details.