Challenge - 5 Problems
React Export-Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this React component import?
Given two files,
Header.js and App.js, where Header.js exports a component as export default function Header() { return <h1>Welcome</h1>; } and App.js imports it as import Header from './Header'; and renders <Header />, what will be displayed on the page?React
/* Header.js */ export default function Header() { return <h1>Welcome</h1>; } /* App.js */ import React from 'react'; import Header from './Header'; export default function App() { return ( <div> <Header /> </div> ); }
Attempts:
2 left
💡 Hint
Check how the component is exported and imported using default export.
✗ Incorrect
When a component is exported as default, it can be imported with any name without curly braces. Rendering will display the returned JSX, which is an
with 'Welcome'.
📝 Syntax
intermediate2:00remaining
Which import statement correctly imports a named export?
If a React component is exported as
export function Footer() { return <footer>Bye</footer>; }, which import statement correctly imports it in another file?React
export function Footer() { return <footer>Bye</footer>; }
Attempts:
2 left
💡 Hint
Named exports require curly braces in import.
✗ Incorrect
Named exports must be imported using curly braces with the exact exported name. Option A uses correct syntax.
🔧 Debug
advanced2:00remaining
Why does this import cause an error?
Given
export default function Nav() { return <nav>Menu</nav>; } in Nav.js, why does import { Nav } from './Nav'; cause an error?React
/* Nav.js */ export default function Nav() { return <nav>Menu</nav>; } /* Another file */ import { Nav } from './Nav'; export default function App() { return <Nav />; }
Attempts:
2 left
💡 Hint
Check the difference between default and named exports and imports.
✗ Incorrect
Default exports must be imported without curly braces. Using curly braces tries to import a named export which does not exist, causing an error.
❓ state_output
advanced2:00remaining
What is the output when importing a component with a typo?
If a component is exported as
export default function Sidebar() { return <aside>Links</aside>; } and imported as import SideBar from './Sidebar'; (note the uppercase B), what happens when rendering <SideBar />?React
/* Sidebar.js */ export default function Sidebar() { return <aside>Links</aside>; } /* App.js */ import SideBar from './Sidebar'; export default function App() { return <SideBar />; }
Attempts:
2 left
💡 Hint
Default exports can be imported with any name regardless of case.
✗ Incorrect
Default exports can be imported with any variable name, so the case difference in the import name does not affect rendering.
🧠 Conceptual
expert2:00remaining
Which statement about exporting and importing React components is true?
Consider these statements about exporting and importing React components. Which one is true?
Attempts:
2 left
💡 Hint
Think about how named exports and imports work in JavaScript modules.
✗ Incorrect
Named exports must be imported with curly braces and the exact exported name. Default exports can be imported with any name without braces.