React学习之Profiler
文章目录
能力:测量渲染一个React应用多久渲染一次以及渲染一次的代价,目的是为了识别出应用中渲染较慢的部分。
Usage:可用在React树的任何地方以测量渲染该部分所带来的开销。
Demo:
render() {
return (
<App>
<Profiler id="Navigation" onRender={callback}>
<Navigation props={...props} />
</Profiler>
<Main />
</App>
);
}onRender回调:
React会在Profiler包含的组件树中的任何组件”提交“一个更新的时候去调用这个回调函数,其参数描述了渲染了什么和花费了多久。
function onRenderCallback (
id, // 发生提交的Profiler树的id
phase, // 'mount'/'update'
actualDuration, // 本次更新commited花费的时间
baseDuration, // 不使用memoization时渲染整棵树所需的时间
startTime, // 本次更新中react渲染开始的时间
commitTime, // 本次更新中react commited的时间
interactions // 本次更新interaction的集合
){
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论