Both of these are valid.
Method 1 provides named exports. The key here is that you can export more than one thing. This should be used instead of exporting an object with multiple properties. When you import a module with named exports, use import {a, b} from c
.
Method 2 provides the default export. There can be only one default export. This is primarily used when you are exporting a single thing, like a class
, or a single function
that you expect to be used without any additional support. When you import a module with a default export, use import d from c
.
Note that you can use both! so if you have a major, primary function with a handful of occasionally used helpers, you can export
the helpers, and export default
the primary. When you import a module and need both kinds of exports, use import d, {a, b} from c
.
One other option is that you can get named exports by listing them at the end of your module, like so: export {a,b,c}
. You can also rename them export {a as $a, b as c}
.
I got all of this from this article, which is the best source for up-to-date es6 module information that I've been able to find.