This component does work:
export class Template extends React.Component {
render() {
return (
<div> component </div>
);
}
};
export default Template;
If i remove last row, it doesn't work.
Uncaught TypeError: Cannot read property 'toUpperCase' of undefined
I guess, I don't understand something in es6 syntax. Isn't it have to export without sign "default"?
Exporting without
default
means it's a "named export". You can have multiple named exports in a single file. So if you do this,then you have to import these exports using their exact names. So to use these components in another file you'd have to do,
Alternatively if you export as the
default
export like this,Then in another file you import the default export without using the
{}
, like this,There can only be one default export per file. In React it's a convention to export one component from a file, and to export it is as the default export.
You're free to rename the default export as you import it,
And you can import default and named exports at the same time,