score:192

Accepted answer

ES6 doesn't allow export default const. You must declare the constant first then export it:

const Header = () => {
  return <pre>Header</pre>
};
export default Header;

This constraint exists to avoid writting export default a, b, c; that is forbidden: only one variable can be exported as default

score:13

You can also use a function declaration instead of assignment:

export default function Header() {
    return <pre>Header</pre>
}

In your example, you already use curly brackets and return so this is apparently matching with your needs with no compromise.

score:21

you can do it in two ways

const ComponentA = props => {
  return <div>{props.header}</div>;
};

export default ComponentA;

2)

export const ComponentA = props => {
  return <div>{props.header}</div>;
};

if we use default to export then we import like this

import ComponentA from '../shared/componentA'

if we don't use default to export then we import like this

import { ComponentA } from '../shared/componentA'

score:49

Just as a side note. You could technically export default without declaring a variable first.

export default () => (
  <pre>Header</pre>
)

Related Query

More Query from same tag