A Short Guide to Component Naming

by Angela Fisher, Front-end Developer

1. Use Descriptive Names

The most important rule when naming components is to be descriptive. Your component names should clearly indicate what the component does or represents. Avoid generic names like Component1 or MyComponent.

Component naming examples

Instead of Button1, use PrimaryButton or SubmitButton. This makes your code self-documenting and easier for other developers (including future you) to understand.

2. Follow Consistent Conventions

Establish naming conventions early in your project and stick to them. Whether you choose PascalCase, camelCase, or kebab-case, consistency is key. Most React projects use PascalCase for component names.

Here are some common conventions:

  • PascalCase: UserProfile, NavigationBar
  • Prefixes: Modal, Card, Form
  • Suffixes: Container, Wrapper, Provider

3. Avoid Abbreviations

While it might be tempting to shorten component names, abbreviations can make your code harder to understand. UserNavigationComponent is better than UsrNavComp.

Component structure diagram

The only exception might be widely understood abbreviations in your domain, but even then, err on the side of clarity.

4. Consider the Component Hierarchy

When naming components that are part of a larger system, consider their relationship to parent and child components. This helps create a logical structure:

  • UserCardUserCardHeader, UserCardBody, UserCardFooter
  • ProductListProductListItem, ProductListFilter

5. Make It Fun (But Professional)

While maintaining professionalism, don't be afraid to inject some personality into your component names when appropriate. A LoadingSpinner could be a LoadingDancer in the right context, as long as the team understands and agrees.

Remember, the goal is to make your code readable, maintainable, and enjoyable to work with. Good component naming is an investment in your future self and your team.

Tell us about your project

Our offices

  • Copenhagen
    1 Carlsberg Gate
    1260, København, Denmark
  • Billund
    24 Lego Allé
    7190, Billund, Denmark