Challenge - 5 Problems
Fallback UI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Suspense fallback UI display initially?
Consider this React component using Suspense with a fallback UI. What will the user see first when this component renders?
React
import React, { Suspense } from 'react'; const LazyComponent = React.lazy(() => import('./LazyComponent')); export default function App() { return ( <Suspense fallback={<div>Loading content...</div>}> <LazyComponent /> </Suspense> ); }
Attempts:
2 left
💡 Hint
Think about what Suspense's fallback prop does while waiting for lazy components.
✗ Incorrect
The fallback prop in Suspense shows the specified UI while the lazy component is loading. Here, it shows 'Loading content...'.
❓ state_output
intermediate2:00remaining
What is the output when ErrorBoundary catches an error?
Given this React component with an ErrorBoundary and fallback UI, what will be rendered if the child component throws an error?
React
import React, { Component } from 'react'; class ErrorBoundary extends Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { return { hasError: true }; } render() { if (this.state.hasError) { return <h1>Something went wrong.</h1>; } return this.props.children; } } function BuggyComponent() { throw new Error('Bug!'); } export default function App() { return ( <ErrorBoundary> <BuggyComponent /> </ErrorBoundary> ); }
Attempts:
2 left
💡 Hint
ErrorBoundary catches errors and shows fallback UI instead of crashing.
✗ Incorrect
The ErrorBoundary catches errors in its children and renders the fallback UI <h1>Something went wrong.</h1> instead of crashing.
📝 Syntax
advanced2:00remaining
Which option correctly uses Suspense with a fallback UI?
Identify the correct syntax to use React Suspense with a fallback UI while loading a lazy component.
Attempts:
2 left
💡 Hint
Suspense is a component that wraps children and takes fallback as a prop.
✗ Incorrect
The correct syntax wraps the lazy component inside <Suspense fallback=...> and closes it after the children.
🔧 Debug
advanced2:00remaining
Why does this fallback UI never show?
This React code uses Suspense with a fallback, but the fallback UI never appears even though the lazy component takes time to load. Why?
React
import React, { Suspense } from 'react'; const LazyComp = React.lazy(() => import('./LazyComp')); export default function App() { return ( <div> <LazyComp /> <Suspense fallback={<div>Loading...</div>} /> </div> ); }
Attempts:
2 left
💡 Hint
Check how Suspense and lazy components are nested.
✗ Incorrect
Suspense must wrap the lazy component to catch its loading state. Here, Suspense is separate, so fallback UI never shows.
🧠 Conceptual
expert2:00remaining
What is the main benefit of using fallback UI patterns in React?
Why do React developers use fallback UI patterns like Suspense fallback or ErrorBoundary fallback in their apps?
Attempts:
2 left
💡 Hint
Think about what users see when parts of the app are slow or broken.
✗ Incorrect
Fallback UI patterns help keep the app responsive and friendly by showing loading messages or error notices instead of blank or crashed screens.