0
0
Reactframework~20 mins

Fallback UI patterns in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Fallback UI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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>
  );
}
AThe text 'Loading content...' until LazyComponent finishes loading
BNothing is shown until LazyComponent loads
CAn error message is shown if LazyComponent fails to load
DThe LazyComponent content appears immediately without fallback
Attempts:
2 left
💡 Hint
Think about what Suspense's fallback prop does while waiting for lazy components.
state_output
intermediate
2: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>
  );
}
AThe error message 'Bug!' is displayed on the screen
BThe app crashes and shows a blank page
CNothing is rendered because of the error
D<h1>Something went wrong.</h1>
Attempts:
2 left
💡 Hint
ErrorBoundary catches errors and shows fallback UI instead of crashing.
📝 Syntax
advanced
2: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.
A<Suspense><LazyComp fallback={<div>Loading...</div>} /></Suspense>
BReact.Suspense({ fallback: <div>Loading...</div> }, <LazyComp />)
C<Suspense fallback={<div>Loading...</div>}><LazyComp /></Suspense>
D<Suspense fallback={<div>Loading...</div>} /> <LazyComp />
Attempts:
2 left
💡 Hint
Suspense is a component that wraps children and takes fallback as a prop.
🔧 Debug
advanced
2: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>
  );
}
ASuspense must wrap the lazy component; here it is separate, so fallback never triggers
BLazyComp is not lazy loaded properly, so fallback is skipped
CFallback UI only shows on errors, not loading
DSuspense fallback must be a string, not a React element
Attempts:
2 left
💡 Hint
Check how Suspense and lazy components are nested.
🧠 Conceptual
expert
2: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?
ATo automatically retry loading components multiple times without user action
BTo improve user experience by showing meaningful UI during loading or errors instead of blank or broken screens
CTo reduce the bundle size by removing components that fail to load
DTo prevent React from rendering any UI until all components are fully loaded
Attempts:
2 left
💡 Hint
Think about what users see when parts of the app are slow or broken.