By default, React does performance optimization out of the box. So when do we have to do performance optimization?
Some rules for performance optimization:
Find the area where it causing performance bottleneck.
Measure before and after Optimization.
Check whether performance issues persist in production mode.
Sometimes doing nothing is better than doing something.
Must have a performance budget.
Must know what causes web slowness whether front end or back end.
Before optimizing react performance, optimize other issues that are causing performance issues like Image loading, font loading, Js loading etc.
Some of the areas we can consider in react we can think of optimization.
To avoid unnecessary re-rendering of components - Identify which nested components causing re- rendering of other components in the tree.
Identify what chunk of JS files is required to render components avoid to sending all all JS files in one bundle.
Use react built-in features to optimize performance like performance hooks - useMemo, useCallback , useTransition, useDeferredValue and for code splitting we can use dynamic import with lazy function, Suspense api , context api.
Use a Build tool like Webpack or any other tools.
Happy Learning 🙂