0
0
Reactframework~5 mins

Error boundaries concept in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an error boundary in React?
An error boundary is a React component that catches JavaScript errors anywhere in its child component tree, logs those errors, and displays a fallback UI instead of the crashed component tree.
Click to reveal answer
intermediate
Which lifecycle method is used in class components to catch errors for error boundaries?
The lifecycle method static getDerivedStateFromError(error) is used to update state when an error is caught, and componentDidCatch(error, info) is used to log the error or perform side effects.
Click to reveal answer
intermediate
Can functional components be error boundaries in React 19+?
No, currently only class components can be error boundaries because error boundary methods rely on lifecycle methods not available in functional components.
Click to reveal answer
beginner
What happens to the UI when an error boundary catches an error?
The error boundary renders a fallback UI, which is a safe and user-friendly message or component, instead of the broken component tree that caused the error.
Click to reveal answer
beginner
Why should you use error boundaries in a React app?
Error boundaries prevent the entire React app from crashing due to errors in parts of the UI. They improve user experience by showing fallback UI and help developers catch and log errors.
Click to reveal answer
Which React component type can be an error boundary?
AStateless components
BFunctional components with hooks
CPure components
DClass components
What method updates state when an error is caught in an error boundary?
AgetDerivedStateFromError
BcomponentDidCatch
CrenderError
DcomponentWillCatch
What does an error boundary do when it catches an error?
AReloads the page
BLogs the error and shows fallback UI
CIgnores the error
DRestarts the app
Can error boundaries catch errors in event handlers?
ANo, error boundaries do not catch errors in event handlers
BOnly in class components
COnly if wrapped in try-catch
DYes, always
What is a good fallback UI for an error boundary?
AA blank screen
BThe error stack trace
CA friendly message explaining something went wrong
DReload button only
Explain how error boundaries improve user experience in React apps.
Think about what happens when a part of the UI breaks and how error boundaries help.
You got /4 concepts.
    Describe the lifecycle methods involved in creating an error boundary class component.
    Focus on methods that catch errors and update UI.
    You got /3 concepts.