Description
Restoring Fast Refresh when using React.lazy
Problem
Fast Refresh can't properly handle React.lazy
.
Solution
Replace dynamic imports to the regular imports
Benefits
- restored developer experience with Fast Refresh
- can catch syntax errors instantly(in comparison, using "dynamic import" the code executes only when it loaded)
Caveats
- use only in development environment
- import source must be a regular string
CRA and customize-cra
Usage with-
Enable Fast Refresh:
-
Using customize-cra-react-refresh addon
-
Coming soon, but didn't work yet. Using CRA env variable FAST_REFRESH. Read more here
-
-
Install the plugin
npm install --save-dev babel-plugin-transform-react-lazy
- Use the plugin
// config-overrides.jsconst override addBabelPlugin = ;const addReactRefresh = ; moduleexports = ;