Error Boundary là React component bắt JavaScript errors trong component tree con và hiển thị fallback UI thay vì crash toàn app.
- Chỉ có thể tạo với Class Component implement
getDerivedStateFromError(set error state) vàcomponentDidCatch(log error). - Thư viện react-error-boundary cung cấp
ErrorBoundarycomponent tiện dụng hơn.
An Error Boundary is a React component that catches JavaScript errors anywhere in its child component tree and displays a fallback UI instead of crashing the whole app.
- It can only be created with a Class Component that implements
getDerivedStateFromError(to set the error state) andcomponentDidCatch(to log the error). - The react-error-boundary library provides a convenient
ErrorBoundarycomponent for function-component-based projects.