简体   繁体   English

如何检查组件中的渲染浪费

[英]how to check wasted renders in component react

我正在尝试在React应用中调试性能问题,有任何方法或'devtools'或任何方法来检查组件的性能以防止浪费的渲染失败

You can use https://github.com/welldone-software/why-did-you-render , its a more maintained up to date version of why-did-you-update ( https://github.com/maicki/why-did-you-update ) , it will print warnings in your console whenever an unnecessary re-render happens in one of your components. 您可以使用https://github.com/welldone-software/why-did-you-render ,它是why-did-you-update的更新版本( https://github.com/maicki/ why-did-you-update ),只要其中一个组件发生不必要的重新渲染,它就会在控制台中显示警告。

Common optimisations you can do to prevent unnecessary renders include using PureComponent instead of Component, or use React.memo for function components, as well as hoist styles/object literals and function declarations outside of your render functions as they return a new reference every time. 您可以采取的常见优化措施是防止不必要的渲染,包括使用PureComponent代替Component或对函数组件使用React.memo以及渲染函数之外的提升样式/对象常量和函数声明,因为它们每次都会返回新的引用。

You can check https://reactjs.org/docs/perf.html 您可以检查https://reactjs.org/docs/perf.html

Specifically take a look on printwasted https://reactjs.org/docs/perf.html#printwasted 具体看一下printwasted https://reactjs.org/docs/perf.html#printwasted

“Wasted” time is spent on components that didn't actually render anything, eg the render stayed the same, so the DOM wasn't touched “浪费”的时间花费在实际上没有渲染任何东西的组件上,例如,渲染保持不变,因此DOM没有被触及

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM