Medium
How to Properly Implement Error Boundary Methods in React Components
You're implementing error boundaries in your React application. What's wrong with this implementation, and which answer correctly implements the missing methods?
1class ErrorBoundary extends React.Component {2 constructor(props) {3 super(props);4 this.state = { hasError: false, error: null };5 }67 // Missing implementation8 ____________________9 ____________________1011 render() {12 if (this.state.hasError) {13 return (14 <div className="error-container">15 <h2>Something went wrong.</h2>16 <details>{this.state.error.toString()}</details>17 </div>18 );19 }20 return this.props.children;21 }22}