MOCKSTACKS
EN
Questions And Answers

More Tutorials









React Performance


You can't improve something you can't measure. To improve the performance of React components, you should be able to measure it. ReactJS provides with addon tools to measure performance. Import the react-addons-perf

module to measure the performance

import Perf from 'react-addons-perf' // ES6
var Perf = require('react-addons-perf') // ES5 with npm
var Perf = React.addons.Perf; // ES5 with react-with-addons.js
You can use below methods from the imported Perf module:
Perf.printInclusive()
Perf.printExclusive()
Perf.printWasted()
Perf.printOperations()
Perf.printDOM()

The most important one which you will need most of the time is Perf.printWasted() which gives you the tabular representation of your individual component's wasted time.

Tips & Tricks


When two nodes are not of the same type, React doesn't try to match them - it just removes the first node from the DOM and inserts the second one. This is why the first tip says

1. If you see yourself alternating between two components classes with very similar output, you may want to
make it the same class.

2. Use shouldComponentUpdate to prevent component from rerender, if you know it is not going to change,
for example

shouldComponentUpdate: function(nextProps, nextState) {
 return nextProps.id !== this.props.id;
}


Conclusion

In this page (written and validated by ) you learned about React Performance . What's Next? If you are interested in completing React tutorial, your next topic will be learning about: React Server Side Rendering.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.