Component names must start with a capital letter. <UserCard /> renders your component. <userCard /> is treated as an HTML tag (which doesn’t exist) and silently fails.
JSX is a syntax extension that lets you write HTML-like code inside JavaScript. It’s not actual HTML — it gets compiled to JavaScript function calls.
Copy
// What you write (JSX)const element = <h1 className="title">Hello</h1>;// What the browser sees (JavaScript)const element = React.createElement('h1', { className: 'title' }, 'Hello');
You never write the React.createElement version. JSX does it for you. But knowing it’s just JavaScript under the hood helps explain the rules.
// ❌ Error: Adjacent JSX elements must be wrappedfunction UserCard() { return ( <h2>Sarah Chen</h2> <p>sarah@example.com</p> );}// ✅ Wrap in a parent elementfunction UserCard() { return ( <div> <h2>Sarah Chen</h2> <p>sarah@example.com</p> </div> );}// ✅ Or use a Fragment (no extra DOM element)function UserCard() { return ( <> <h2>Sarah Chen</h2> <p>sarah@example.com</p> </> );}
<>...</> is a Fragment — it groups elements without adding an extra DOM node. Use it when you don’t need a wrapper div.
// HTML allows self-closing tags to be open// <img src="photo.jpg">// <br>// <input type="text">// JSX requires all tags to be closed<img src="photo.jpg" /><br /><input type="text" />
You can only use expressions inside {}, not statements. {if (x) ...} won’t work. Use ternary operators or && instead. {x ? "yes" : "no"} and {x && "shown"} are the React way.
The double braces {{ }} are: outer {} for “this is JavaScript”, inner {} for “this is an object.”
Copy
// You can also define styles separatelyconst cardStyle = { padding: "16px", borderRadius: "8px", backgroundColor: "#f9fafb", boxShadow: "0 1px 3px rgba(0,0,0,0.1)",};function Card({ children }) { return <div style={cardStyle}>{children}</div>;}
Inline styles work but aren’t ideal for large apps. For most projects, use CSS files (import './App.css'), CSS modules, or a library like Tailwind CSS. Inline styles are fine for dynamic values like width: ${percentage}%.