0

I understood that we export components to be able to import into some other file and to do so we use 'Named exports'and 'default exports', But i am indeed not sure about following things,

1.Are there any specific contexts to choose between any of them?

2.'Are named exports' and 'default exports' interchangeable?

  • https://stackoverflow.com/questions/42478661/difference-between-export-and-export-default-in-javascript. This might be a possible explanation. – Aman Seth Jul 12 '17 at 07:57
  • @Aman Seth-Thank you, This is solved my query. But could you suggest any a bit detailed documentation regarding this –  Jul 12 '17 at 08:02

1 Answers1

1

It is mostly question of style and consistency. Rough rule of thumb might be:

  • If you have just one item that you would like to export from module, use default export
  • If you have several equally important items that you would like to export from module, use named exports
  • If you have several items that you would like to export, but one of them stands out by far, than use default export for that item, and named for others.

One thing though, is to try to stick to your decisions, and do not try to endlessly move some items from default to named and vice versa, since code that uses your module might need updating as well.

Davorin Ruševljan
  • 4,353
  • 21
  • 27