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

When to Split vs Keep Components Together

Recognize the signals for splitting a component into its own file versus keeping small helper components in the same file with their parent.

When to Split vs Keep Components Together

You'll learn: How to decide whether a small component should live in its own file or stay with its parent component.

The Decision Point

Not every component deserves its own file. Just because you can extract something doesn't mean you should. The key is recognizing the signals that tell you when to split versus when to keep things together.

Keep Components Together When...

Helper components are tiny and highly specific. If a component only exists to organize JSX within one parent and is 3-5 lines, keeping it in the same file reduces jumping between files.

They're not reused anywhere else. A UserCardHeader that's only ever used inside UserCard? Keep it colocated. You'll see them together every time you edit.

Splitting would add more confusion than clarity. If extracting a 10-line component means creating a new file with imports and exports that's harder to understand than the original, don't split.

Split Into Separate Files When...

The component is reused in multiple places. Once two or more parent components need the same child, it deserves its own file for DRY principles.

The component is complex or growing. If it handles significant logic, has multiple state values, or exceeds ~50 lines, splitting improves focus and testability.

Splitting would improve readability. A parent with 200 lines becomes clearer when you extract logical sections into named components, even if they're only used once.

Think Like an Organizer

Imagine organizing kitchen tools. Specialty items you only use for one recipe? Keep them near that recipe. Tools used everywhere? Give them their own drawer. Same principle applies to components.

Key Takeaway: Split components into separate files when they're reused, complex, or improve clarity. Keep small, single-use helpers colocated with their parent to reduce file-hopping overhead.