A component is a function that returns JSX. See plain JavaScript values flow into the markup through curly braces.
React · beginner · 6 min · 7 steps · free
export default function Profile() {
const name = 'Ada Lovelace';
const born = 1815;
const years = 2026 - born;
const titleStyle = { color: 'purple', fontSize: 24 };
return (
<div className="profile">
<h2 style={titleStyle}>{name}</h2>
<p>Born in {born}, {years} years ago.</p>
<p>{name.length > 10 ? 'A long name' : 'A short name'}</p>
</div>
);
}Profile. A component is just a function: React calls it to find out what the screen should show.name = "Ada Lovelace".born = 1815.years = 2026 − 1815 = 211.fontSize, not font-size.Profile returns JSX. It looks like HTML, but it is JavaScript: {name} puts the value of name into the markup. Nothing is on the page yet.className became class, and the style object became CSS.Answer: 5. The expression is worked out first.
Answer: className. class is a reserved word in JavaScript.