Course contentsShow
← React
Lesson 865 of 2,39623. useMemo and useCallbackFree lesson

React's Re-render Behavior Without Memoization

How every state update causes a full component re-render, re-executing all function bodies and recreating all values.

React's Re-render Behavior Without Memoization

What you'll learn: Why React components recreate everything from scratch on every state update by default.

The Default Behavior

When a component's state changes in React, the entire component function re-executes. This means every line of code inside that function runs again, every variable gets recreated, every object literal gets rebuilt, and every function gets redefined. React doesn't skip anything—it runs the whole function body fresh each time.

This happens because React doesn't know which parts of your component depend on the changed state. To be safe, it just re-runs everything.

Why This Matters

Consider a component with several variables:

function Dashboard() {
  const [count, setCount] = useState(0);
  
  // All of these get recreated on EVERY render:
  const expensiveCalculation = processData(largeDataset);
  const config = { theme: 'dark', locale: 'en' };
  const handleClick = () => console.log('clicked');
  
  return <div onClick={handleClick}>{count}</div>;
}

When count changes, React re-executes the entire function. expensiveCalculation runs again (even if the data hasn't changed), a new config object is created, and a new handleClick function is created. All of this happens even though none of these values actually need to change.

The Analogy

Think of React like a chef who makes your entire meal from scratch every time you ask for more salt. You only wanted salt adjusted, but they're chopping vegetables, boiling water, and mixing ingredients all over again.

Key Takeaway: By default, React re-creates every value and re-executes every line inside a component on each state update, regardless of whether those values actually depend on the changed state.