Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we use the facebook React addons Perf class?

Trying a very simple thing, and am getting errors "TypeError: Cannot read property 'counts' of undefined"

Here's the hello world example code.

https://gist.github.com/joshuacalloway/ae5b184c485956314d1c

like image 904
jcalloway Avatar asked Mar 03 '15 00:03

jcalloway


2 Answers

I know this question is old - but in case someones fall in here (as I did) here it's how you should do it nowdays..

You import the react addon you want separately

import Perf from 'react-addons-perf'

and then you can do whatever you want with it.. Example: Assign it to the window object so you can use it in the console.

window.Perf = Perf
like image 106
André Junges Avatar answered Nov 08 '22 15:11

André Junges


I was getting the same error calling Perf.start() in the render function where I wanted to start profiling, seemed to be a timing issue, so I just started recording perf before I rendered anything and then called my print functions when I wanted to see what was going on (pseudocode):

In app.js:

//var React = require('react'); // DONOTCHECKIN
var React = require('react/addons');
// ...

function run() {
  // DONOTCHECKIN
  window.Perf = React.addons.Perf; // save for later console calls
  React.addons.Perf.start();
  // ...

Then in the console I can invoke:

Perf.printWasted()

Hope this helps.

like image 5
aaron Avatar answered Nov 08 '22 16:11

aaron