Capítulo 11 de 116
A React component is just a JavaScript function, capitalized, that returns JSX markup — components are the reusable UI building block everything else in React composes from, the same way <article>/<h1>/<li> compose an HTML document.
export default (standard JS, marks the file's main function for import elsewhere) + function ComponentName() {} (capitalized name — required, or the JSX tag won't be recognized as a component) + a return of JSX markup.return, it must be wrapped in parentheses — otherwise JavaScript's automatic semicolon insertion silently returns undefined.<Profile />. Casing is the signal React uses: lowercase (<section>) means "host HTML element," capitalized (<Profile />) means "my component."Profile definition becomes three <img> tags in the final HTML.function Profile() {} inside function Gallery() {} is slow and causes state bugs (see Ch 30, Preserving and Resetting State). Always declare components at the top level; pass data down via props (Ch 15) instead.function Profile() {
return <img src="..." alt="Katherine Johnson" />;
}
export default function Gallery() {
return (
<section>
<h1>Amazing scientists</h1>
<Profile />
<Profile />
</section>
);
}
Gallery) rendering a child component (Profile) multiple times — the core composition mechanic of React.export default vs. named export controls how the file gets imported elsewhere — the full rules are in Ch 12.