diff --git a/beta/src/content/learn/your-first-component.md b/beta/src/content/learn/your-first-component.md index 23fab3c4..df1591f7 100644 --- a/beta/src/content/learn/your-first-component.md +++ b/beta/src/content/learn/your-first-component.md @@ -176,6 +176,37 @@ Components are regular JavaScript functions, so you can keep multiple components Because the `Profile` components are rendered inside `Gallery`—even several times!—we can say that `Gallery` is a **parent component,** rendering each `Profile` as a "child". This is part of the magic of React: you can define a component once, and then use it in as many places and as many times as you like. + + +Components can render other components, but **you must never nest their definitions:** + +```js {2-5} +export default function Gallery() { + // 🔴 Never define a component inside another component! + function Profile() { + // ... + } + // ... +} +``` + +The snippet above is [very slow and causes bugs.](/learn/preserving-and-resetting-state#different-components-at-the-same-position-reset-state) Instead, define every component at the top level: + +```js {5-8} +export default function Gallery() { + // ... +} + +// ✅ Declare components at the top level +function Profile() { + // ... +} +``` + +When a child component needs some data from a parent, [pass it by props](/learn/passing-props-to-a-component) instead of nesting definitions. + + + Your React application begins at a "root" component. Usually, it is created automatically when you start a new project. For example, if you use [CodeSandbox](https://codesandbox.io/) or [Create React App](https://create-react-app.dev/), the root component is defined in `src/App.js`. If you use the framework [Next.js](https://nextjs.org/), the root component is defined in `pages/index.js`. In these examples, you've been exporting root components.