Importing and Exporting Components
Importing and Exporting Components
Here both Profile and Gallery have been moved out of App.js
into a new file called Gallery.js. Now you can change App.js
to import Gallery from Gallery.js:
import Gallery from './Gallery.js';
export default function App() {
return (
<Gallery />
);
}
Notice how this example is broken down into two
component files now:
1. Gallery.js:
• Defines the Profile component which is only used
2. App.js:
• Imports Gallery as a default import from Gallery.js.
export.
Note
You may encounter files that leave off the .js file extension
like so:
DEEP DIVE
Default vs named exports
Show Details
Note
• Gallery.js:
• Exports the Profile component as a named export
called Profile.
• Exports the Gallery component as a default export.
• App.js:
• Imports Profile as a named import
export.