Command Palette

Search for a command to run...

Hectal
Phase 23: Build, Deploy and Run in Production
React · Exercise 4 of 5 PreviousNext
Advanced

Send render errors to a reporter

When PriceTag crashes, the error boundary shows a fallback, but nobody is told. Pass onCaughtError (and onUncaughtError too) to createRoot so every render error is reported with report(kind, error, errorInfo).

Finish report: it adds one <li> to the list #log (outside React, already in the HTML) with the text <kind>: <message> in <Component>, for example caught: Price is undefined in PriceTag. Get the component name from the first at Name in errorInfo.componentStack.

What Check tests

  1. The price shows and nothing is reported yet
  2. Breaking the price shows the boundary's fallback
  3. Exactly one report was added
  4. The report reads caught: Price is undefined in PriceTag
  5. Uncaught errors are reported too

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.