Một mục mã nguồn mở trong kho dữ liệu GitHub của TopGit: bvaughn/react-error-boundary, 8.0k sao, TypeScript. Simple reusable React error boundary component
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Read the react-error-boundary docs for examples, API reference, and troubleshooting. The docs also include a frequently asked questions guide.
Quick start
Wrap an ErrorBoundary around the part of the tree where you want to show a fallback UI if rendering fails. Your fallback can call resetErrorBoundary to clear the error and retry rendering:
"use client";
import { ErrorBoundary, getErrorMessage } from "react-error-boundary";
export default function App() {
return (
<ErrorBoundary
fallbackRender={({ error, resetErrorBoundary }) => (
<div role="alert">
<p>Something went wrong:</p>
<pre>{getErrorMessage(error)}</pre>
<button onClick={resetErrorBoundary}>Try again</button>
</div>
)}
onError={(error, info) => {
// Log the error to your error reporting service
}}
onReset={() => {
// Reset any state that may have caused the error
}}
>
{/* Components protected by this boundary */}
</ErrorBoundary>
);
}
What errors are caught?
This package is built on top of React error boundaries, so it follows React's rules for what errors are caught.
Error boundaries catch errors thrown while rendering the tree below them.
Error boundaries do not catch errors from:
Server-side rendering
Event handlers
The error boundary itself
Async code that runs after rendering, like setTimeout callbacks or unresolved promises
Event handler and async errors
For event handler errors and async callback errors:
Use useErrorBoundary to pass caught errors to the nearest boundary.
In React 19, useTransition Actions can be an alternative: errors thrown from a function passed to the returned startTransition function are caught by the nearest boundary.
A reusable React error boundary component.
Wrap this component around other React components to "catch" errors and render a fallback UI.
Catches errors thrown while rendering the tree below it.
Does not catch errors from:
Server-side rendering
Event handlers
The error boundary itself
Async code that runs after rendering, like setTimeout callbacks or unresolved promises
Event handler and async errors:
Use useErrorBoundary to pass caught errors to the nearest boundary
In React 19, errors thrown from a function passed to the startTransition function returned by useTransition
are caught by the nearest boundary
ℹ️ The component provides several ways to render a fallback: fallback, fallbackRender, and FallbackComponent.
Refer to the documentation to determine which is best for your application.
ℹ️ This is a client component. You can only pass props to it that are serializable or use it in files that have a "use client"; directive.
Required props
None
Optional props
Name
Description
onError
Optional callback to enable e.g. logging error information to a server.
error Value that was thrown; typically an instance of Error
info React "component stack" identifying where the error was thrown
onReset
Optional callback to be notified when an error boundary is reset so React can retry the failed render.
resetKeys
When changed, these keys will reset a triggered error boundary.
This can be useful when an error condition may be tied to some specific state (that can be uniquely identified by key).
See the documentation for examples of how to use this prop.
fallback
Static content to render in place of an error if one is thrown.
<ErrorBoundary fallback={<div className="text-red">Something went wrong</div>} />
FallbackComponent
React component responsible for returning a fallback UI based on a thrown value.
<ErrorBoundary FallbackComponent={Fallback} />
fallbackRender
Render prop function responsible for returning a fallback UI based on a thrown value.
Convenience hook for imperatively showing or dismissing error boundaries.
⚠️ This hook must only be used within an ErrorBoundary subtree.
Returns: The currently visible error (if one has been thrown), a resetBoundary method to reset and retry the nearest active error boundary, and a showBoundary method to display an error in the nearest error boundary
FAQ
ErrorBoundary cannot be used as a JSX component
This error can be caused by a version mismatch between react and @types/react. To fix this, ensure that both match exactly, e.g.:
bvaughn/react-error-boundary có phải mã nguồn mở không?
Có — bvaughn/react-error-boundary phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/bvaughn/react-error-boundary.
bvaughn/react-error-boundary có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho bvaughn/react-error-boundary. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
bvaughn/react-error-boundary có trang demo không?
Dự án có trang chủ ở https://react-error-boundary-lib.vercel.app. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
bvaughn/react-error-boundary còn đang phát triển không?
Commit gần nhất trên bvaughn/react-error-boundary là 3 ngày trước (theo timestamp GitHub). Repo có 230 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
bvaughn/react-error-boundary dùng license gì?
bvaughn/react-error-boundary phát hành theo license MIT. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
Đọc thêm về bvaughn/react-error-boundary ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/bvaughn/react-error-boundary là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về react-error-boundary?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về react-error-boundary.