How to Improve React App Performance with Simple Hacks πŸš€

Lokesh Prajapati
4 min read1 day ago

--

How to Improve React App Performance with Simple Hacks (2025 Guide) πŸš€

πŸš€ Why React Performance Matters

A slow React app can frustrate users, increase bounce rates, and even impact SEO. Instead of a complete rewrite, you can use simple optimizations to significantly boost your React app’s speed and efficiency.

Let’s explore proven techniques to improve performance while keeping the code clean and scalable.

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

1️⃣ Prevent Unnecessary Re-Renders with React.memo() 🧠

By default, React re-renders child components even if their props haven’t changed. This can be inefficient.

βœ… Solution: Use React.memo() to prevent unnecessary re-renders by memoizing components.

❌ Unoptimized Version

const ChildComponent = ({ name }) => {
console.log("Child Rendered!");
return <h2>Hello, {name}!</h2>;
};

const ParentComponent = () => {
const [count, setCount] = React.useState(0);
return (
<div>
<button onClick={() => setCount(count + 1)}>Increase</button>
<ChildComponent name="John" />
</div>
);
};

πŸ”Ή Issue: Even though name="John" never changes, ChildComponent re-renders every time the button is clicked.

βœ… Optimized with React.memo()

const ChildComponent = React.memo(({ name }) => {
console.log("Child Rendered!");
return <h2>Hello, {name}!</h2>;
});

πŸ”₯ Now, ChildComponent only re-renders if name changes!

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

2️⃣ Optimize Lists with key and React Virtualization πŸ”₯

Large lists can slow down your app due to excessive re-renders.

βœ… Solution:

  • Use a unique key (not index) for lists.
  • Use react-window for rendering large lists efficiently.

❌ Unoptimized List

{items.map((item, index) => (
<div key={index}>{item.name}</div>
))}

⚠️ Issue: Using index as key can cause unnecessary re-renders.

βœ… Optimized with Unique key

{items.map((item) => (
<div key={item.id}>{item.name}</div>
))}

πŸ”Ή Why? React efficiently tracks list updates based on unique id.

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

πŸš€ Supercharged: Virtualized List for Large Data

import { FixedSizeList as List } from "react-window";

const MyList = ({ items }) => (
<List height={400} itemCount={items.length} itemSize={50} width="100%">
{({ index, style }) => <div style={style}>{items[index].name}</div>}
</List>
);

πŸ”₯ Now, React only renders visible items, boosting performance!

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

3️⃣ Optimize Functions with useCallback() and useMemo() πŸ”„

❌ Problem: Unnecessary Function Recreation

Each re-render creates new function instances, causing unwanted re-renders in child components.

βœ… Solution:

Use useCallback() for Function Memoization

const ParentComponent = () => {
const [count, setCount] = React.useState(0);

const handleClick = React.useCallback(() => {
console.log("Button Clicked!");
}, []);

return <ChildComponent onClick={handleClick} />;
};

πŸ”Ή Now, handleClick doesn’t change on every render! πŸš€

βœ… Optimize Expensive Calculations with useMemo()

If a component performs heavy calculations, it slows down the app. Use useMemo() to cache results.

const expensiveCalculation = (num) => {
console.log("Calculating...");
return num * 2;
};

const MyComponent = ({ num }) => {
const result = React.useMemo(() => expensiveCalculation(num), [num]);
return <div>{result}</div>;
};

πŸ”₯ Now, the function only runs when num changes!

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

4️⃣ Optimize Images and Assets πŸ“Έ

Large images slow down page load time. Use:
βœ… Lazy Loading (Load images only when needed)
βœ… Next.js Image Optimization (For Next.js projects)

πŸ”Ή React Lazy Loading Example

const LazyImage = ({ src, alt }) => (
<img loading="lazy" src={src} alt={alt} width="300" />
);

πŸ”₯ Now, images only load when they appear on the screen!

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

5️⃣ Split Code with React.lazy() & Suspense πŸš€

Instead of loading everything at once, load only what the user needs using code-splitting.

βœ… Solution: Use React.lazy() to dynamically load components.

❌ Without Code-Splitting (Slow)

import HeavyComponent from "./HeavyComponent";

⚠️ Issue: Loads even if not needed!

βœ… With Code-Splitting (Faster)

const HeavyComponent = React.lazy(() => import("./HeavyComponent"));

const App = () => (
<React.Suspense fallback={<div>Loading...</div>}>
<HeavyComponent />
</React.Suspense>
);

πŸ”₯ Now, HeavyComponent loads only when needed!

β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

πŸš€ Final Thoughts

πŸ”Ή Summary of Performance Hacks

Optimization: β€” β€” β€” β€” Benefit:

React.memo() β€” β€” β€” β€” Prevents unnecessary re-renders
Keys & Virtualization β€” β€” β€” β€” Optimizes list rendering
useCallback() & useMemo() β€” β€” β€” β€” Prevents unnecessary function recreations
Code-Splitting with React.lazy() β€” β€” β€” β€” Reduces initial load time
Lazy Loading Images β€” β€” β€” β€” Improves loading speed

βœ… Which of these techniques have you used before?
πŸ’¬ Let me know in the comments! 😊

--

--

Lokesh Prajapati
Lokesh Prajapati

Written by Lokesh Prajapati

Front-end-developer | Web Designer | Shopify Experts - https://lokesh-prajapati.vercel.app/

No responses yet