Trung BìnhReact iconReact

Error Boundary là gì và cách tạo?

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 ErrorBoundary component tiện dụng hơn.

Xem toàn bộ React cùng filter theo level & chủ đề con.

Mở danh sách React