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

bvakiti picture bvakiti · Oct 24, 2017 · Viewed 21.2k times · Source

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?

Answer

Ben picture Ben · Oct 24, 2017

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.