0
0
Reactframework~5 mins

Exporting and importing components in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of exporting a component in React?
Exporting a component allows it to be used in other files by making it available outside its own file.
Click to reveal answer
beginner
What is the difference between a default export and a named export?
A default export lets you export one main thing from a file and import it without curly braces. Named exports allow exporting multiple things and require curly braces when importing.
Click to reveal answer
beginner
How do you import a default exported component named <code>Header</code> from a file <code>Header.js</code>?
Use <code>import Header from './Header';</code> to import the default exported component.
Click to reveal answer
beginner
How do you import a named exported component called <code>Footer</code> from <code>Footer.js</code>?
Use <code>import { Footer } from './Footer';</code> with curly braces to import a named export.
Click to reveal answer
intermediate
Why might you choose named exports over default exports in React components?
Named exports help keep imports clear and allow exporting multiple components from one file, making code easier to manage and avoid naming conflicts.
Click to reveal answer
Which syntax correctly exports a React component as the default export?
Aexport { MyComponent };
Bexport function MyComponent() {}
Cimport MyComponent from './MyComponent';
Dexport default function MyComponent() {}
How do you import a named export called Button from a file?
Aimport Button from './Button';
Bimport { Button } from './Button';
Cimport * as Button from './Button';
Dexport { Button } from './Button';
What happens if you try to import a default export using curly braces?
AIt imports all named exports.
BIt works fine.
CIt causes an error or undefined import.
DIt imports the file as a module object.
Which statement is true about named exports?
AYou can export multiple named components from one file.
BNamed exports must be imported without curly braces.
CYou can only have one named export per file.
DNamed exports are the same as default exports.
If a file exports a component as default, how do you rename it on import?
AUse <code>import NewName from './file';</code>
BYou cannot rename default exports.
CUse <code>import { NewName } from './file';</code>
DUse <code>export default NewName from './file';</code>
Explain how to export and import a React component using default export.
Think about how you share one main component from a file.
You got /3 concepts.
    Describe the difference between named exports and default exports in React components.
    Consider how you might organize many components in one file.
    You got /3 concepts.