You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/13-modules/02-import-export/article.md
+6-4
Original file line number
Diff line number
Diff line change
@@ -321,7 +321,7 @@ export {default as User} from './user.js'; // re-export default
321
321
322
322
Why would that be needed? Let's see a practical use case.
323
323
324
-
Imagine, we're writing a "package": a folder with a lot of modules, with some of the functionality exported outside (tools like NPM allow us to publish and distribute such packages), and many modules are just "helpers", for internal use in other package modules.
324
+
Imagine, we're writing a "package": a folder with a lot of modules, with some of the functionality exported outside (tools like NPM allow us to publish and distribute such packages, but we don't have to use them), and many modules are just "helpers", for internal use in other package modules.
325
325
326
326
The file structure could be like this:
327
327
```
@@ -378,7 +378,7 @@ export {default as User} from './user.js';
378
378
379
379
The default export needs separate handling when re-exporting.
380
380
381
-
Let'ssaywehave`user.js`, andwe'd like to re-export class `User` from it:
381
+
Let's say we have `user.js` with the `export default class User`and would like to re-export it:
382
382
383
383
```js
384
384
// 📁 user.js
@@ -387,7 +387,9 @@ export default class User {
387
387
}
388
388
```
389
389
390
-
1. `export User from './user.js'` won'twork. Whatcangowrong?... Butthat's a syntax error!
390
+
We can come across two problems with it:
391
+
392
+
1.`export User from './user.js'` won't work. That would lead to a syntax error.
391
393
392
394
To re-export the default export, we have to write `export {default as User}`, as in the example above.
393
395
@@ -399,7 +401,7 @@ export default class User {
399
401
export {default} from'./user.js'; // to re-export the default export
400
402
```
401
403
402
-
Such oddities of re-exporting the default exportareoneofthereasonswhysomedevelopersdon't like them.
404
+
Such oddities of re-exporting a default exportareoneofthereasonswhysomedevelopersdon't like default exports and prefer named ones.
0 commit comments