ReactQuestion 14 of 28
How can you handle errors?
Answer out loud or in your head first, then compare.
Answer
For async code:
JavaScript
try {
const response =
await fetch(...);
} catch (error) {
setError(error);
}In the UI, handle:
loading
success
empty
errorFor errors during rendering, use Error Boundaries.
In larger apps it's worth having monitoring, e.g. Sentry.
How did it go? Be honest — “Not yet” puts the question on your review list.