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

One Component Per File Convention

Learn the standard practice of one component per file, named exports vs default exports, and when to colocate multiple related components.

One Component Per File Convention

What you'll learn: Why React developers typically place each component in its own file and when it's okay to break that rule.

The Standard Practice

In React, the most common pattern is one component per file. This means if you have a Button component, it lives in its own Button.jsx file (or Button.js). If you have a Header component, it gets its own Header.jsx file.

Think of it like organizing your kitchen: you don't dump all your utensils in one drawer. Forks go in the fork section, knives in the knife section. Same idea—each component gets its own space.

Why This Matters

When you put each component in its own file:

  • Finding things is easier — need to fix the Button? You know exactly where to look
  • Collaboration improves — teammates can work on different components without file conflicts
  • Imports are cleaner — import Button from './Button' tells you exactly what you're getting

When to Co-locate

You can keep multiple components in one file when:

  • One component is only used by another (like a tiny helper component)
  • The components are tightly related and tiny (under 20 lines each)
  • Splitting them would feel like overkill

For example, if UserProfile has a private AvatarBadge that's never used elsewhere, keeping both in UserProfile.jsx is perfectly fine.

The Real-World Rule

Start with one component per file. Only combine them when it genuinely makes the code simpler to understand. If you're debating whether to split, split.

Key Takeaway: One component per file is the standard for a reason—it keeps your codebase organized, readable, and team-friendly. Break the rule only when co-locating genuinely improves clarity.