Usman Ahmed’s Post

For a long time, I tried to stop React from re-rendering. Turns out, I was solving the wrong problem. React is already fast at rendering. The real issue isn’t re-renders—it’s 𝐰𝐡𝐚𝐭 𝐲𝐨𝐮 𝐝𝐨 𝐝𝐮𝐫𝐢𝐧𝐠 𝐞𝐚𝐜𝐡 𝐫𝐞𝐧𝐝𝐞𝐫. If your component runs expensive logic every time it renders, performance will suffer no matter how many optimizations you add. A simple example: const sortedUsers = users.sort((a, b) => a.age - b.age) This runs on every render. A better approach: const sortedUsers = useMemo(  () => users.slice().sort((a, b) => a.age - b.age),  [users] ) Now the sorting only happens when `users` actually change. This small shift changed how I think about performance. The goal is not fewer renders—it’s 𝐥𝐞𝐬𝐬 𝐰𝐨𝐫𝐤 𝐩𝐞𝐫 𝐫𝐞𝐧𝐝𝐞𝐫. Once you focus on that, tools like `useMemo` and `useCallback` start making sense instead of being overused blindly. 💡 Here’s what I apply in real projects: ✔️ Avoid heavy computations directly inside render ✔️ Use `useMemo` only for expensive operations ✔️ Measure before optimizing—don’t guess React performance isn’t about tricks. It’s about understanding where the real cost is. 💬 𝐖𝐡𝐞𝐧 𝐝𝐢𝐝 𝐑𝐞𝐚𝐜𝐭 𝐩𝐞𝐫𝐟𝐨𝐫𝐦𝐚𝐧𝐜𝐞 𝐟𝐢𝐧𝐚𝐥𝐥𝐲 “𝐜𝐥𝐢𝐜𝐤” 𝐟𝐨𝐫 𝐲𝐨𝐮? 👉 Follow Usman Ahmed for more Updates! #ReactJS #FrontendEngineering #WebPerformance #JavaScript #CleanCode #SoftwareEngineering #ReactHooks

  • text

To view or add a comment, sign in

Explore content categories