The Components Folder: Shared vs Feature-Specific
What you'll learn: How to decide whether a component belongs in a shared folder or lives alongside feature code.
When building a React app, you'll quickly accumulate components. Some are reusable across your entire app (buttons, modals, form inputs), while others are specific to a single feature (a checkout wizard, a product filter panel). The question becomes: where should each component live?
The Kitchen Analogy
Think of your codebase like a kitchen. Shared components are like basic utensils (knives, spoons, measuring cups) that you use everywhere—they belong in a common drawer. Feature-specific components are like specialized tools (a sushi rolling mat, pasta maker) that only matter for certain recipes—those stay near where you use them.
Shared Components
Place truly reusable UI pieces in a dedicated folder:
src/
components/ ← Shared across features
Button/
Modal/
Input/
These components have no business logic tied to a specific feature. A Button doesn't know about your shopping cart or user profile—it just renders a clickable element with styling.
Feature-Specific Components
Keep feature-bound components close to their feature:
src/
features/
checkout/
CheckoutWizard.jsx ← Only used in checkout
PaymentForm.jsx
profile/
AvatarUploader.jsx ← Only used in profile
This follows colocation: related files live together. If you delete the checkout feature, all its components go with it.
The Decision Rule
Ask: "Will I use this component in multiple, unrelated features?" If yes → shared folder. If no → feature folder.
Key Takeaway: Shared components live in a common components/ folder for reuse everywhere; feature-specific components stay colocated with their feature to maintain clear boundaries and make code easier to delete or refactor.