Performance Cost of Inline Styles
You'll learn why inline styles can hurt performance by creating new objects on every render, breaking React's optimization strategies.
The Hidden Cost of style={{}}
Every time you write style={{ color: 'blue' }} directly in JSX, JavaScript creates a brand new object. Even if the properties are identical, each render produces a different object reference. This seemingly innocent pattern defeats React's ability to skip work.
Here's the problem: React's memoization tools (React.memo, useMemo, useCallback) rely on reference equality to determine if something changed. When you pass style={{ margin: 10 }} to a component, that's a new object every single render—so React thinks the props changed, even when the actual values didn't.
Why This Matters
Think of it like handing someone a new piece of paper with the same shopping list written on it every time you see them. They have to read it again to confirm nothing changed, even though the contents are identical. That's wasted effort.
// ❌ Creates new object every render - breaks memoization
<ExpensiveChild style={{ padding: 20 }} />
// ✅ Stable reference - memoization works
const childStyle = { padding: 20 };
<ExpensiveChild style={childStyle} />
The component ExpensiveChild will re-render unnecessarily in the first example because style is a "new" prop every time, even if wrapped in React.memo. The second example creates the object once outside the render cycle, maintaining the same reference.
This becomes critical in lists, animations, or frequently updating components where you've carefully memoized children to avoid expensive work.
Key Takeaway: Inline style objects create new references on every render, preventing memoization from working and forcing unnecessary re-renders in optimized components—extract styles to stable references when performance matters.