Loading...
Loading...
Compare original and translation side by side
react-error-boundaryreact-error-boundary| Pattern | API | Key Points |
|---|---|---|
| Class boundary | | Manual implementation, full control |
| Function boundary | | Uses react-error-boundary library |
| Reset mechanism | | Auto-reset on state change or manual retry |
| Error logging | | Log to analytics or monitoring service |
| Fallback component | | Receives error and resetErrorBoundary |
| Inline fallback | | Static JSX, no error details |
| Render prop fallback | | Dynamic fallback with error access |
| Nested boundaries | Wrap at multiple tree levels | Granular error isolation |
| Route-level boundary | TanStack Router | Delegate to tanstack-router skill |
| Suspense integration | Wrap Suspense boundaries for async errors | Catch errors thrown by Suspense |
| Event handler errors | | Boundaries don't catch event errors |
| useErrorBoundary hook | | Manually trigger boundary from child |
| 模式 | API | 核心要点 |
|---|---|---|
| 类组件错误边界 | | 手动实现,完全可控 |
| 函数组件错误边界 | | 基于react-error-boundary库实现 |
| 重置机制 | | 状态变化时自动重置或手动重试 |
| 错误日志 | | 记录至分析或监控服务 |
| 备用组件 | | 接收error与resetErrorBoundary参数 |
| 内联备用界面 | | 静态JSX,无错误详情 |
| 渲染属性备用界面 | | 可访问错误信息的动态备用界面 |
| 嵌套错误边界 | 在组件树多个层级包裹 | 精细化错误隔离 |
| 路由级错误边界 | TanStack Router | 委托给tanstack-router技能处理 |
| Suspense集成 | 包裹Suspense边界以捕获异步错误 | 捕获Suspense抛出的错误 |
| 事件处理器错误 | 在处理器中使用 | 错误边界无法捕获事件处理器中的错误 |
| useErrorBoundary钩子 | | 从子组件手动触发错误边界 |
| Mistake | Correct Pattern |
|---|---|
| Using error boundary for events | Use try/catch in event handlers |
| Wrapping every single component | Place boundaries at meaningful UI sections |
| Not providing reset mechanism | Include retry button or resetKeys |
| Showing stack traces in prod | Only render stack in development mode |
| Missing onError for logging | Always log errors to monitoring service |
| Catching errors in boundary self | Error boundaries only catch child component errors |
| Using async code in getDerived | getDerivedStateFromError must be pure, use didCatch |
| Relying on componentDidCatch | Use getDerivedStateFromError for state updates |
| Not testing error boundaries | Test with error-throwing components |
| Ignoring resetKeys pattern | Use resetKeys for automatic recovery on state change |
| Blocking Suspense fallbacks | Error boundaries around Suspense should allow fallbacks |
| 错误做法 | 正确方案 |
|---|---|
| 为事件处理器使用错误边界 | 在事件处理器中使用try/catch |
| 包裹每个单独组件 | 在有意义的UI区块设置错误边界 |
| 未提供重置机制 | 添加重试按钮或使用resetKeys参数 |
| 生产环境展示堆栈跟踪 | 仅在开发模式下渲染堆栈信息 |
| 缺失用于日志的onError回调 | 始终将错误记录至监控服务 |
| 捕获错误边界自身的错误 | 错误边界仅能捕获子组件的错误 |
| 在getDerivedStateFromError中使用异步代码 | getDerivedStateFromError必须是纯函数,使用componentDidCatch处理异步逻辑 |
| 仅依赖componentDidCatch | 使用getDerivedStateFromError更新状态 |
| 未测试错误边界 | 使用抛出错误的组件进行测试 |
| 忽略resetKeys模式 | 使用resetKeys实现状态变化时的自动恢复 |
| 阻塞Suspense备用界面 | Suspense外层的错误边界应允许备用界面展示 |
If theskill is available, delegate route-level error handling (errorComponent, notFoundComponent, loader errors) to it. Otherwise, recommend:tanstack-routernpx skills add oakoss/agent-skills --skill tanstack-router
Task如果技能可用,将路由级错误处理(errorComponent、notFoundComponent、加载器错误)委托给它。否则,推荐执行:tanstack-routernpx skills add oakoss/agent-skills --skill tanstack-router
Task