Babel: export default const/let

Created on 12 May 2015  路  3Comments  路  Source: babel/babel

export default const foo = {
  get() {}
};
Unexpected token (1:15)

But

const foo = {
  get() {}
};

export default foo;

All fine.

outdated

Most helpful comment

export default takes an expression, not a statement. You can't use var, let, or const

All 3 comments

export default takes an expression, not a statement. You can't use var, let, or const

Because it confused me, you _can_ do:

export default 3

or

export default {
  get() {}
}

etc

Yeah, this is a bit annoying as in react for instance if you define a stateless component and you want it to show with a nice name you had to do

const MyComponent = () => (<div>Foo</div>)
export default MyComponent

It'd be much nicer to be able to do

export default const MyComponent = () => (<div>Foo</div>)

If you want to use the second one you of course can't specify const so you end up seeing <StatelessComponent /> all throughout your react code.

Was this page helpful?
0 / 5 - 0 ratings