Course contentsShow
← React
Lesson 191 of 2,3966. Component BasicsFree lesson

Container and Presentational Components

Separating logic-heavy containers from presentational components for cleaner architecture and reusability.

Container and Presentational Components

You'll learn how to split components into logic-driven "containers" and display-focused "presentational" components for better organization and reusability.

What This Pattern Means

Imagine a restaurant kitchen: the container is like the chef who handles all the recipe logic, ingredient prep, and cooking decisions. The presentational component is like the waiter who beautifully plates and serves the food—they don't cook, they just present what they're given.

In React, container components handle the complex logic—fetching data, managing calculations, or coordinating multiple pieces of state. They pass the results down to presentational components, which focus purely on how things look and receive everything they need through props.

Why Separate Them?

When you mix logic and presentation in one component, it becomes harder to:

  • Understand what the component does at a glance
  • Reuse the presentational parts with different data
  • Test each concern independently

By separating them, your presentational components become simple, predictable, and easy to reuse. Your containers stay focused on "what to show" rather than "how to show it."

The Basic Pattern

A container might calculate which users to display based on filters, then pass clean data to a presentational component. The presentational component just receives users as a prop and maps over them to create the UI—it doesn't know where those users came from or why they're filtered that way.

This creates a clear boundary: containers think, presentational components display.

Key Takeaway: Separate logic-heavy containers from simple presentational components to create cleaner, more reusable architectures where each component has a single, clear responsibility.