Marcus Nguyen
Software Engineer
React's render cycle is one of the biggest performance costs. Prevent wasteful re-renders by:
const ExpensiveComponent = React.memo(({ data }) => {
return <div>{data.title}</div>;
});
Why load everything upfront?
const LazySettings = React.lazy(() => import('./Settings'));
Global state is powerful — but overuse can cause unwanted re-renders.
Tips:
<img src="/banner.webp" loading="lazy" alt="Banner" />
Expensive operations like scroll, resize, or map updates should be throttled:
const throttled = useRef(_.throttle(handleScroll, 200));
While JavaScript’s .map(), .filter(), and .reduce() methods offer clean and expressive syntax, they introduce overhead in performance-critical code — especially in rendering-heavy React apps or environments like Electron.
❌ Example (more expressive, but slower in large arrays):
const ids = logs.filter(log => log.active).map(log => log.id);
âś… Example (faster and more memory-efficient):
const ids = [];
for (const log of logs) {
if (log.active) ids.push(log.id);
}
In one of my Electron apps processing 10k+ map features:
React performance isn't about one magic fix — it's a mindset. Start by measuring, then optimize carefully and iteratively. Many of these tips are simple yet effective, and they can dramatically improve the user experience.