20 React Performance Hacks
π 20 React Performance Hacks for Building Ultra-Fast UIs
β‘ Supercharge Your Components, Speed Up Renders & Deliver Lightning-Fast Experiences!
If your React application is slowing down as it growsβ¦ youβre not alone π React is powerful, but without tuning, even small mistakes can cause re-renders, laggy UI, and wasted computation.
This guide includes 20 powerful performance hacks β each with examples β to help you build ultra-fast React apps ππ¨
β 1. Use React.memo() to Prevent Unnecessary Re-renders
When to use: Component receives the same props repeatedly.
Example:
const UserCard = React.memo(function UserCard({ name }) {
return <h2>{name}</h2>;
});
β 2. Use useCallback for Stable Function References
Re-created functions trigger re-renders.
const handleClick = useCallback(() => {
console.log("Clicked");
}, []);
β 3. Use useMemo for Expensive Computations
Memoize heavy logic.
const result = useMemo(() => slowFunction(data), [data]);
β 4. Lazy Load Components (React.lazy)
Load pages only when needed.
const Dashboard = React.lazy(() => import("./Dashboard"));
β 5. Use Code Splitting with Suspense
Make bundles smaller.
<Suspense fallback={<Loader />}>
<Dashboard />
</Suspense>
β 6. Avoid Anonymous Functions in JSX
Anonymous functions create new references.
β Bad:
<button onClick={() => send()}>Click</button>
β Good:
<button onClick={handleClick}>Click</button>
β 7. Avoid Inline Objects in JSX
Inline objects recreate new memory references.
const style = { color: "red" };
return <h1 style={style}>Hi</h1>;
β 8. Use Pagination + Infinite Scroll for Large Lists
Never render 10,000 items at once.
β 9. Use React Window / Virtualization for Huge Lists
react-window renders only visible items.
import { FixedSizeList as List } from "react-window";
β 10. Debounce Inputs to Avoid Repeated State Updates
Prevent rapid state changes.
const debounced = useCallback(debounce(fn, 500), []);
β 11. Use Throttling for Scroll Events
Avoid 1000 scroll events/second.
β 12. Batch Multiple State Updates
React automatically batches updates.
setCount(c => c + 1);
setFlag(f => !f);
β 13. Avoid Storing Derived Data in State
Computable values = donβt store in state.
β Bad:
const [fullName, setFullName] = useState(first + last);
β 14. Keep Components Small & Focused
Large components re-render too often.
Break UI into reusable pieces.
β 15. Use Production Build (npm run build)
Minified + tree-shaken + optimized.
β 16. Load Images Efficiently β Lazy Load, WebP, CDN
Speed up UI visually.
<img loading="lazy" src="image.webp" />
β 17. Use key Properly in Lists
Keys help React identify changed items.
<ul>
{users.map(u => <li key={u.id}>{u.name}</li>)}
</ul>
β 18. Memoize Context Values (useMemo)
Context triggers re-renders β stabilize values.
const value = useMemo(() => ({ user }), [user]);
β 19. Keep State Local, Not Global
Avoid putting everything in Context or Redux.
Local state renders fewer components.
β 20. Use Chrome Performance Profiler to Identify Bottlenecks
Real devs measure first. The profiler reveals:
- Slow renders
- Repeated renders
- Heavy logic
- Memory issues
π§ Mini Example: Slow Component β Optimized
β Slow:
function ProductList({ products }) {
return products.map(p => (
<ProductCard product={p} onClick={() => buy(p)} />
));
}
β Optimized:
const ProductCard = React.memo(function ProductCard({ product, onClick }) {
return <div onClick={onClick}>{product.name}</div>;
});
function ProductList({ products }) {
const handleBuy = useCallback((p) => buy(p), []);
return products.map(p => (
<ProductCard key={p.id} product={p} onClick={() => handleBuy(p)} />
));
}
π Final Thoughts
React is powerful β but performance needs intentional engineering. Applying even 5β7 of these hacks can make your UI noticeably faster. Apply all 20 β You get an ultra-responsive, smooth, Google-friendly UI πβ¨
© Lakhveer Singh Rajput - Blogs. All Rights Reserved.