Skip to main content

Command Palette

Search for a command to run...

πŸ“˜ React Mastery Series β€” Day 7

Published
β€’2 min readβ€’View as Markdown
πŸ“˜ React Mastery Series β€” Day 7
S

Frontend Developer | React & JavaScript | Building production-ready web apps Developer with 1.5+ years of experience, currently focused on React, Redux, and full-stack development. Sharing practical tutorials, concepts, and project learnings.

How React Rendering Works & Performance Basics (Beginner Friendly)

Many developers use React daily but don’t fully understand:

πŸ‘‰ When does React re-render?
πŸ‘‰ Why does UI update automatically?
πŸ‘‰ How to avoid unnecessary renders?

Let’s understand this clearly and simply.


πŸ”„ What is Rendering in React?

Rendering means:

πŸ‘‰ React runs your component function and updates the UI.

React renders when:

βœ… State changes
βœ… Props change
βœ… Parent component re-renders


πŸ“Œ Simple Example

import { useState } from "react";

function App() {
  const [count, setCount] = useState(0);

  console.log("Rendered");

  return (
    <>
      <p>{count}</p>
      <button onClick={() => setCount(count + 1)}>
        Increase
      </button>
    </>
  );
}

πŸ‘‰ Every click triggers re-render.


⚑ Does React reload the whole page?

❌ No!

React uses Virtual DOM:

β€’ Compares old UI with new UI
β€’ Updates only changed parts

This makes React fast.


🚫 Common Cause of Unnecessary Renders

setCount(count); // causes render even if value same

Better:

setCount(prev => prev);

(React may skip if no change)


🎯 Performance Tip #1 β€” Keep state minimal

Don’t store values that can be derived.

Bad ❌

const [fullName, setFullName] = useState(first + last);

Good βœ…

const fullName = first + last;

πŸš€ Performance Tip #2 β€” Use React.memo (quick intro)

const Child = React.memo(({ name }) => {
  console.log("Child rendered");
  return <p>{name}</p>;
});

πŸ‘‰ Prevents re-render if props don’t change.


⚠ Important Truth

React re-rendering is NORMAL and FAST.
Only optimize when you see performance issues.


βœ… Key Takeaways

βœ” React re-renders on state/props change
βœ” Virtual DOM updates efficiently
βœ” Keep state minimal
βœ” Optimize only when needed


πŸ”œ Coming Next in Series

Day 8 β€” Lifting State Up & Component Communication

(Real project pattern!)


πŸ’¬ Did you know parent re-renders affect children?

Thank you for reading! πŸ™Œ

More from this blog