0

React newb ― please be gentle.

So I have my first empty react project created through create-react-app. And there's the example snippets available at https://reactjs.org/, the very home page of the site, which I incorporated into my empty project. Now I'm not sure what's the react convention around exporting stuff, as in:

export default App

frankly, I was not able to find documentation regarding that under react docs. Can you kindly explain, or point me in the right direction as per relevant documentation?

Thanks!

matanster
  • 15,072
  • 19
  • 88
  • 167
  • 1
    I'm confused by your question, are you asking what does `export` do? If so, export does what it says. It exports something. In this case, a Component called `TodoApp` why? you export components whenever you want to use them with other components. – Curious13 Mar 21 '18 at 20:58
  • You're right, question revised – matanster Mar 21 '18 at 21:23
  • Possible duplicate of [What is "export default" in javascript?](https://stackoverflow.com/questions/21117160/what-is-export-default-in-javascript) – Cory Danielson Mar 21 '18 at 21:35

1 Answers1

0

Not sure If I understand you correctly, but you ask about the difference between named export and export default statements.

It has nothing to do with react. It's an ES6 (also known as ECMAScript 6) feature, module loader.

ECMAScript 6 (ES6, often referred to as “Harmony”) is the upcoming sixth major release of the ECMAScript language specification. ECMAScript is the “proper” name for the language commonly referred to as JavaScript.

Please read about export syntax on MDN and read about this ES6 feature

Here some simple examples

// app.js - main file
import Module, { namedExport } from './module/path/file';

// module/path/file.js

const namedExport = 'I am named export';
export default function () { return 'I am default export' }
loelsonk
  • 3,570
  • 2
  • 16
  • 23