by Angela Fisher, Front-end Developer
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.
Instead of Button1, use PrimaryButton or SubmitButton. This
makes your code self-documenting and easier for other developers (including future you) to
understand.
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:
UserProfile, NavigationBarModal, Card, FormContainer, Wrapper, Provider
While it might be tempting to shorten component names, abbreviations can make your code harder to
understand. UserNavigationComponent is better than UsrNavComp.
The only exception might be widely understood abbreviations in your domain, but even then, err on the side of clarity.
When naming components that are part of a larger system, consider their relationship to parent and child components. This helps create a logical structure:
UserCard → UserCardHeader, UserCardBody,
UserCardFooter
ProductList → ProductListItem, ProductListFilter
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.