Coding task · JavaScript and React course · Module 10: React Ecosystem and Future
Practice: Error Boundaries
An error boundary is a class component: the static getDerivedStateFromError(error) method returns the state in which render shows a fallback view, and componentDidCatch(error, info) is for reporting (info.componentStack tells you in which component the error happened). A boundary catches render errors of its children, so wrapping every panel separately isolates a failure. After fixing the cause you have to clear the boundary state (reset) so that the children render again.
Task
Finish the MissionBoundary class, the error boundary for the bridge panels. The fuel sensor is broken and its panel throws an error, while the other panels must keep working. ___BLANK1___: getDerivedStateFromError returns the new state with an error field that holds the caught error ({ error }). ___BLANK2___: componentDidCatch reports the crash with reportCrash(error, info.componentStack). ___BLANK3___: when the state holds an error, render returns the view from this.props.renderFallback, passing it the error from state and the this.reset function (the class stays free of JSX). Clicking Restart sensor repairs the sensor and resets the boundary, so the fuel panel comes back showing 50%.