我对如何利用React的性能工具感到困惑。我当前的用法如下所示:

var Perf = React.addons.Perf;
Perf.start();
this.setState({
    newState: newStateObject,
}, function(){
    Perf.printInclusive();
    Perf.stop();
});

这不会在页面上呈现任何内容并脱口而出
Uncaught TypeError: Cannot read property 'counts' of undefined

最佳答案

参见https://github.com/facebook/react/issues/3389#issuecomment-79236067

看来Perf.start()仅在组件生命周期之外被调用时才有效。因此,在启动应用程序之前先调用它,或者在触发尝试监视的事件之前直接从浏览器的控制台调用它。

09-25 18:35
查看更多