Priyadarshan Kumar’s Post

I wasted months trying to stop React re-renders. Using React.memo, useCallback… every trick in the book. Turns out, I was solving the wrong problem. Re-renders are not the issue. React is fast. The real problem is what you do during a render. The mistake 👇 Running expensive operations every time: const sortedUsers = users.sort((a, b) => a.age - b.age); Every render = sorting again With large data, this kills performance. The fix ✅ const sortedUsers = useMemo( () => users.slice().sort((a, b) => a.age - b.age), [users] ); Now it only runs when "users" changes. The mindset shift: ❌ Stop re-renders ✅ Reduce work per render That one shift made React performance finally click for me. What was your biggest React “aha” moment? #ReactJS #JavaScript #FrontendDevelopment #WebDevelopment #ReactDeveloper #Programming #SoftwareEngineering #PerformanceOptimization

  • No alternative text description for this image

Stop making AI slop comparisons, this harms people who are actually trying to learn. This is neither a real-world example nor a real comparison, and the click handler just disappeared.

This applies only to old React versions, in React 19 the new compiler handles it automatically, making the manual optimization obsolete. There might be some edge cases it might be needed though.

Great mindset shift 👏 Most devs over-focus on preventing re-renders, but the real win is reducing expensive work during render. That change in thinking is a game changer.

Sounds good Priyadarshan Kumar Want to add bit - If you can use slice before sorting it helps to avoid mutations. It runs when & only dep reference change

This example is "INCORRECT" it will still re-render because the data is an array and whenever parent get re-render this component will re-render with it.

Like
Reply

To avoid mutation use toSorted instead of sort

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories