๐—ง๐—ต๐—ฒ ๐—ฅ๐—ฒ๐—ฎ๐—น ๐—–๐—ผ๐˜€๐˜ ๐—ผ๐—ณ ๐—ฅ๐—ฒ-๐—ฟ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ฟ๐˜€ ๐—ถ๐—ป ๐—ฅ๐—ฒ๐—ฎ๐—ฐ๐˜

I used to think React performance issues came from slow APIs or bad database queries. I thought React was fast enough to handle anything.

I was wrong.

As my application grew, the UI became sluggish. The backend was fast. The network was quick. Yet, the user experience felt heavy.

The problem was not React. The problem was unnecessary re-renders.

One state update was triggering massive parts of the component tree to run again. I was asking React to do way more work than it needed to do.

Every render has a cost. React must run functions, evaluate hooks, and compare virtual DOM trees. One render is cheap. Hundreds of unnecessary renders are expensive.

I used the React Profiler to find the source. I found that many small components were rendering repeatedly.

Here is how I fixed it:

The results were massive.

A screen that took 800ms to update now takes 60ms. The app has no new features. It just stops doing useless work.

Performance is an architecture problem.

Stop trying to fix performance with hooks alone. Start designing better component structures.

Source: https://dev.to/akshay_sarak/the-real-cost-of-re-renders-in-react-2j77