Capítulo 12 de 116
As components multiply, split them into separate files using standard JavaScript export/import — a file can have at most one default export but any number of named exports, and the export style you pick dictates the required import syntax.
App.js, or per-page in a file-based router) that other components eventually get imported into.export default function Button() {} → import Button from './Button.js' — the import name is arbitrary, doesn't need to match.export function Button() {} → import { Button } from './Button.js' — the name must match on both sides.'./Gallery.js' and './Gallery' both work; the explicit .js is closer to native ES Modules semantics.export default () => {}) — an unnamed component function makes debugging harder (stack traces, DevTools).| Syntax | Export statement | Import statement |
|---|---|---|
| Default | export default function Button() {} | import Button from './Button.js'; |
| Named | export function Button() {} | import { Button } from './Button.js'; |
import Banana from './Button.js' still works); named-import names must match the export exactly.Gallery) and a named export (e.g. Profile) simultaneously — the importing file then combines a default import and a { NamedThing } import from the same path.