CodeBlanks Logo Icon CodeBlanks

Naming rules

Learn that component names start with a capital letter and why it matters.

Naming rules

In React, component names use PascalCase: UserCard, ShoppingCart, LoginForm. This separates them from HTML tags.

HTML tags start lowercase: div, span, button. If a component name starts lowercase, React treats it as an HTML tag and it won't work.

Component names should also describe what they do: UserList is clear, Comp1 is vague. Good names make maintenance easier.

Naming meaning

A component name should describe what it does. Header is a clear top bar; Thing says nothing. Teams often follow the what + for what rule: UserAvatar, CartItem, SearchInput.

The file name should match the component name: a UserAvatar.jsx file holds the UserAvatar component. This makes searching easy.

Consistent naming speeds up team talk: when someone hears a name, everyone pictures the same thing.

Practice UserAvatar component

Complete the skeleton. Write a component called UserAvatar that returns <figure> with <img alt="Avatar" /> inside. Don't forget to export.

Starter code

App.jsx
// Write the UserAvatar component here

Sample solution

App.jsx
function UserAvatar() {
  return <figure><img alt="Avatar" /></figure>;
}

export default UserAvatar;

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is a valid component name?

  • userCard
  • user_card
  • UserCard Correct answer
  • user-card

Explanation: UserCard is PascalCase, so it's a valid component name.

2 PascalCase example

Question
Valid component name: ____ (PascalCase).
Answer
Valid component name: ProductCard (PascalCase).

Explanation: ProductCard is PascalCase.

3 Match the naming tips

Term Meaning
UserCard Meaningful name
userCard Wrong
UserCard.jsx File name
User-Card Invalid

All lessons in Beginner