React JSX Capitalization Rules Explained

#reactjs #reactjsdeveloper Why components start with a capital letter in react? Because JSX is just syntax sugar. When you write: <User /> <div /> Babel transforms it into: React.createElement(User, null) React.createElement("div", null) And here’s the key rule: • Lowercase → treated as a string tag ("div", "span") • Capitalized → treated as a JavaScript reference (User) So React understands: • "div" → native DOM element • User → function component → invoke it and continue rendering If you write <user />, the JSX transform emits: React.createElement("user", null) Now React assumes "user" is a host element (like a DOM tag), not your component. So capitalization isn’t stylistic — the JSX transform emits either a string type or a reference type, and React uses that to distinguish host elements from custom components.

I'm glad to see posts like this on LinkedIn. These days, people don't care about such nuances, even though they contribute to a general understanding of the technology.

See more comments

To view or add a comment, sign in

Explore content categories