Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

javascript - Why and when to use default export over named exports in es6 Modules?

I have referred all the questions in stackoverflow. But none of the suggested why and when to use default export.

I just saw that default can be metioned "When there is only one export in a file"

Any other reason for using default export in es6 modules?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Some differences that might make you choose one over the other:

Named Exports

  • Can export multiple values
  • MUST use the exported name when importing

Default Exports

  • Export a single value
  • Can use any name when importing

This article does a nice job of explaining when it would be a good idea to use one over the other.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...