MediumComponent Patterns📖 Theory Question

What is the Container/Presentational pattern? Is it still relevant?

💡

Hint

Smart vs dumb components — data fetching separated from rendering; largely replaced by hooks but the principle remains

Full Answer

The pattern separates data concerns (fetching, state) from UI concerns (rendering, styling):

// ❌ Old way — explicit Container component
function UserListContainer() {
  const [users, setUsers] = useState([]);
  useEffect(() => { fetchUsers().then(setUsers); }, []);
  return ; // pass data down
}

function UserList({ users }) {
  return users.map(u => );
}

// ✅ Modern way — custom hook achieves the same separation
function useUsers() {
  return useQuery(['users'], fetchUsers);
}

// Presentational component stays the same
function UserList({ users }) {
  return users.map(u => );
}

// Consuming component — much simpler
function UsersPage() {
  const { data: users } = useUsers();
  return ;
}

Still relevant principles:

  • Keep components that render UI free of data-fetching — easier to test, reuse in Storybook
  • The separation now lives in custom hooks, not wrapper components
💡 The pattern's goal (separation of concerns) is still correct; the implementation changed. Hooks achieve it more elegantly without extra component nesting.

More Component Patterns Questions

EasyWhat is the Compound Component pattern?EasyWhat is the Render Props pattern and when would you still use it?MediumWhat is the Provider pattern and how do you build a scalable context architecture?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint