DEV Community

Why do React components need to start with capital letters?

Bhat Aasim on September 21, 2024

Why do React components need to start with capital letters? If you’ve ever worked with React, you might have noticed that component names always...
Collapse
 
alexkhotkevich profile image
Alexander

What about const SomeName = "some value" and projects without Babel?

Collapse
 
bhataasim profile image
Bhat Aasim

SomeName simply a variable, not a react component. Capitalization rule will not apply here, because its not being used as a react component here.

Projects without babel, then React.createElement() Api is used Explicitly.

BTW, using Capital letters in Components, helps react to differentiate between Native Elements and custom Components.

Eg.

React.createElement('div'); 
// Interpreted as a native HTML <div> element

React.createElement(MyComponent); 
// Interpreted as a custom React component
Enter fullscreen mode Exit fullscreen mode

If MyComponent is written in lower case (myComponent), React will look for a native HTML element <myComponent> which doesn't exists, causing the app to fail.

Collapse
 
alexkhotkevich profile image
Alexander

I see the point with createElement, but I still can write lower case functional component on a project without Babel and still get the error. So it's not Babel concern, as your article states

Collapse
 
respect17 profile image
Kudzai Murimi

Ahhhha nice!

Collapse
 
bhataasim profile image
Bhat Aasim

Thanks

Collapse
 
rehan72 profile image
Rehan

Thank you 👍

Collapse
 
bhataasim profile image
Bhat Aasim

You are Welcome 😊

Collapse
 
skysung profile image
SkySung

Short and informative thanks!

Collapse
 
bhataasim profile image
Bhat Aasim

Thanks ❣️

Collapse
 
mohit0129 profile image
Mohit

Good information, thanks for providing

Collapse
 
bhataasim profile image
Bhat Aasim

Thanks ❣️

Collapse
 
henriquemsleal profile image
Carlos Henrique Leal

Very good. Thank you!

Collapse
 
bhataasim profile image
Bhat Aasim

Thank You ❣️

Collapse
 
six51099183 profile image
six

Concise and to the point. I love this!

Collapse
 
bhataasim profile image
Bhat Aasim

Thanks Man ❣️

Collapse
 
rishichitnis008 profile image
Rishi Chitnis

Hi, Amazing blog post!!

Collapse
 
rohit_raj profile image
Rohit Raj

New information, thank.❤️