Skip to content

参考

基于 React 19.2 + React DevTools 6.x 编写

速查

  • 安装:浏览器扩展(Chrome/Firefox/Edge)或 npx react-devtools(RN/Safari)
  • 面板:Components ⚛(组件树)+ Profiler ⚛(渲染性能)
  • 选中组件 → $r$r.props / $r.state
  • 编辑 props/state:双击值,页面实时更新
  • 高亮重渲染:Profiler 设置 → Highlight updates
  • 为什么渲染:Profiler 设置 → Record why each component rendered
  • 完整说明见 入门 / 组件树导航 / Props/State/Hooks / Profiler / 高亮与优化 / 独立应用与 RN

两大面板

面板用途
Components ⚛组件树、props/state/hooks/context 检查编辑
Profiler ⚛录制渲染性能、火焰图、为什么渲染、Compiler ✨

Console 引用

变量含义
$r当前选中的组件实例
$r.props它的 props
$r.state它的 state(类组件)

Profiler 工作流

  1. (可选)设置开「Record why each component rendered」
  2. 点录制 / Reload and start profiling
  3. 交互后停止
  4. 看 Flamegraph(耗时层级)/ Ranked(最慢组件)
  5. 点组件看「为什么渲染」
  6. 优化后重录验证

优化手段对照

手段作用
React.memoprops 未变跳过渲染
useMemo缓存计算 / 稳定引用
useCallback稳定函数引用
稳定 key避免列表错误复用
React Compiler自动记忆化(标 ✨)

安装形态

形态命令 / 方式适用
浏览器扩展商店搜「React Developer Tools」网页
standalonenpx react-devtoolsRN / Safari / Electron

官方资源