Skip to content

Commit 40e18e6

Browse files
authored
add react.js section
1 parent 319ae37 commit 40e18e6

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,27 @@ soWhat: 'The export is now \*removed\* from the declaration'
245245
};
246246
export default foo;
247247
```
248+
249+
### React.js - Named Exports
250+
251+
> [source, https://reactjs.org/docs/code-splitting.html#named-exports](https://reactjs.org/docs/code-splitting.html#named-exports)
252+
253+
254+
React.lazy currently only supports default exports. If the module you want to import uses named exports, you can create an intermediate module that reexports it as the default. This ensures that tree shaking keeps working and that you don’t pull in unused components.
255+
256+
```javascript
257+
// ManyComponents.js
258+
export const MyComponent = /* ... */;
259+
export const MyUnusedComponent = /* ... */;
260+
```
261+
262+
```javascript
263+
// MyComponent.js
264+
export { MyComponent as default } from "./ManyComponents.js";
265+
```
266+
267+
```javascript
268+
// MyApp.js
269+
import React, { lazy } from 'react';
270+
const MyComponent = lazy(() => import("./MyComponent.js"));
271+
```

0 commit comments

Comments
 (0)