React · Advanced Patterns

Advanced Patterns Interview Questions
With Answers & Code Examples

3 carefully curated Advanced Patterns interview questions with working code examples and real interview gotchas.

Practice Interactively →← All Categories
3 questions0 beginner0 core3 advanced
Q1Advanced

What is Error Boundary and how do you implement one?

💡 Hint: Class component wrapping the tree — catches render errors and shows fallback UI instead of blank screen

Error Boundaries catch JavaScript errors during rendering, in lifecycle methods, and in constructors of child components. They must be class components (no hook equivalent yet).

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false, error: null };
  }

  // Render phase — update state to show fallback
  static getDerivedStateFromError(error) {
    return { hasError: true, error };
  }

  // Commit phase — log error to monitoring service
  componentDidCatch(error, info) {
    logErrorToSentry(error, info.componentStack);
  }

  render() {
    if (this.state.hasError) {
      return this.props.fallback ?? 

Something went wrong.

; } return this.props.children; } } // Usage — wrap features, not the entire app function App() { return ( }> }> ); } // react-error-boundary library — hook-friendly wrapper import { ErrorBoundary } from 'react-error-boundary';
💡 Error boundaries do NOT catch errors in event handlers, async code (setTimeout, fetch), or SSR. Use try/catch for those. Place boundaries at feature level, not component level — granular boundaries give better UX.
Practice this question →
Q2Advanced

What is the Suspense pattern and data fetching with it?

💡 Hint: Suspend rendering while async work completes — component throws a Promise; Suspense catches it and shows fallback

Suspense lets components "wait" for something before rendering. The component throws a Promise; React catches it and shows the fallback.

// React.lazy — built-in Suspense integration
const Chart = lazy(() => import('./Chart'));

// React Query with Suspense mode
function UserProfile({ id }) {
  // This will suspend (throw) if data isn't ready yet
  const { data: user } = useSuspenseQuery({
    queryKey: ['user', id],
    queryFn: () => fetchUser(id),
  });

  return 

{user.name}

; // Only renders when data is ready } // Wrapping with Suspense function Page() { return ( }> ); } // Nested Suspense — granular loading states function Dashboard() { return ( }> }> {/* loads independently */} ); }
💡 Suspense eliminates the isLoading + early return pattern. The component is always in a "ready" state — Suspense handles the loading state above it. Combine with Error Boundaries for complete coverage.
Practice this question →
Q3Advanced

What is prop spreading and when is it an anti-pattern?

💡 Hint: {...props} forwards all props — useful for wrapper components but can pass wrong props to DOM elements
// ✅ Legitimate use — forwarding unknown props to underlying element
function Button({ variant, className, ...rest }) {
  return (
    
💡 Always destructure custom props before spreading. "Rest" in a component should only contain valid HTML attributes for the element it spreads onto.
Practice this question →

Other React Interview Topics

Rendering StrategiesCore JSType SystemReact FundamentalsFunctionsMicrofrontendsGenericsAsync JSHooksObjectsMonorepoArrays'this' KeywordUtility TypesError HandlingModern JSBundle OptimizationPerformanceDOM & EventsState ManagementClasses & OOPCaching StrategiesComponent PatternsAdvanced TypesAuthenticationReact RouterFormsFrontend SecurityConcurrent ReactServer ComponentsTestingEcosystemNetwork OptimizationCore Web VitalsBrowser APIs

Ready to practice Advanced Patterns?

Get AI feedback on your answers, predict code output, and fix real bugs.

Start Free Practice →