0
0
Reactframework~10 mins

Component naming rules in React - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Component naming rules
Start
Name component
Is first letter uppercase?
NoError: Rename component
Yes
Use PascalCase
Export component
Use component in JSX
Render success
This flow shows how React components must be named starting with uppercase letters using PascalCase to be recognized and rendered correctly.
Execution Sample
React
function MyButton() {
  return <button>Click me</button>;
}

export default MyButton;
Defines a React component named MyButton with uppercase first letter and exports it for use.
Execution Table
StepComponent NameCheck First LetterNaming StyleResult
1MyButtonM (uppercase)PascalCaseValid component name
2myButtonm (lowercase)camelCaseInvalid - React treats as HTML tag
3ButtonB (uppercase)PascalCaseValid component name
4buttonb (lowercase)camelCaseInvalid - React treats as HTML tag
5My_buttonM (uppercase)PascalCase with underscoreValid but not recommended
6my_buttonm (lowercase)camelCase with underscoreInvalid - React treats as HTML tag
💡 React requires component names to start with uppercase letters to distinguish from HTML tags.
Variable Tracker
Component NameInitialCheck First LetterNaming StyleValidity
MyButtonMyButtonMPascalCaseValid
myButtonmyButtonmcamelCaseInvalid
ButtonButtonBPascalCaseValid
buttonbuttonbcamelCaseInvalid
My_buttonMy_buttonMPascalCase with underscoreValid but not recommended
my_buttonmy_buttonmcamelCase with underscoreInvalid
Key Moments - 2 Insights
Why must React component names start with uppercase letters?
React uses the first letter to distinguish components from HTML tags. Lowercase names are treated as HTML elements, so components must start uppercase as shown in execution_table rows 1 and 2.
Can I use underscores in component names?
While React allows underscores if the first letter is uppercase (row 5), it is not recommended. PascalCase without underscores is the standard for clarity and consistency.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which component name is valid and follows React naming rules?
Abutton
BmyButton
CMyButton
Dmy_button
💡 Hint
Check the 'Check First Letter' and 'Result' columns in execution_table rows 1-4.
At which step does React treat the name as an HTML tag instead of a component?
AStep 2
BStep 3
CStep 1
DStep 5
💡 Hint
Look at the 'Result' column for lowercase first letters in execution_table.
If you rename 'myButton' to 'MyButton', how does the validity change?
ABecomes invalid
BBecomes valid
CNo change
DReact throws an error
💡 Hint
Compare rows 1 and 2 in execution_table for the effect of uppercase first letter.
Concept Snapshot
React components must start with uppercase letters.
Use PascalCase naming style (e.g., MyComponent).
Lowercase names are treated as HTML tags.
Avoid underscores; prefer clear PascalCase.
Export components to use them in JSX.
This ensures React renders them correctly.
Full Transcript
In React, component names must start with an uppercase letter to be recognized as components rather than HTML tags. This means using PascalCase naming style like MyButton or Button. Names starting with lowercase letters like myButton or button are treated as HTML elements and will not render as React components. While underscores can be used if the first letter is uppercase, it is not recommended. Following these naming rules ensures React correctly renders your components when used in JSX.