You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/client/createRoot.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,7 +199,7 @@ function Counter() {
199
199
200
200
**If your app is fully built with React, you shouldn't need to create any more roots, or to call [`root.render`](#root-render) again.**
201
201
202
-
From this point on, React will manage the DOM of your entire app. To add more components, [nest them inside the `App` component.](/learn/importing-and-exporting-components) When you need to update the UI, each of your components can do this by [using state.](/reference/react/useState) When you need to display extra content like a modal or a tooltip outside the DOM node, [render it with a portal.](/reference/react-dom/createPortal)
202
+
From this point on, React will manage the DOM of your entire app. To add more components, [nest them inside the `App` component.](/learn/importing-and-exporting-components) When you need to update the UI, each of your components can do this by [using state.](/reference/react/useState) When you need to display extra content like a modal or a tooltip outside the DOM node, [render it with a Portal.](/reference/react-dom/createPortal)
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/common.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ All built-in browser components, such as [`<div>`](https://developer.mozilla.org
26
26
27
27
These special React props are supported for all built-in components:
28
28
29
-
*`children`: A React node (an element, a string, a number, [a portal,](/reference/react-dom/createPortal) an empty node like `null`, `undefined` and booleans, or an array of other React nodes). Specifies the content inside the component. When you use JSX, you will usually specify the `children` prop implicitly by nesting tags like `<div><span /></div>`.
29
+
*`children`: A React node (an element, a string, a number, [a Portal,](/reference/react-dom/createPortal) an empty node like `null`, `undefined` and booleans, or an array of other React nodes). Specifies the content inside the component. When you use JSX, you will usually specify the `children` prop implicitly by nesting tags like `<div><span /></div>`.
30
30
31
31
*`dangerouslySetInnerHTML`: An object of the form `{ __html: '<p>some html</p>' }` with a raw HTML string inside. Overrides the [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) property of the DOM node and displays the passed HTML inside. This should be used with extreme caution! If the HTML inside isn't trusted (for example, if it's based on user data), you risk introducing an [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting) vulnerability. [Read more about using `dangerouslySetInnerHTML`.](#dangerously-setting-the-inner-html)
To create a portal, call `createPortal`, passing some JSX, and the DOM node where it should be rendered:
27
+
To create a Portal, call `createPortal`, passing some JSX, and the DOM node where it should be rendered:
28
28
29
29
```js
30
30
import { createPortal } from'react-dom';
@@ -42,23 +42,23 @@ import { createPortal } from 'react-dom';
42
42
43
43
[See more examples below.](#usage)
44
44
45
-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events bubble up from children to parents according to the React tree.
45
+
A Portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a Portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events bubble up from children to parents according to the React tree.
46
46
47
47
#### Parameters {/*parameters*/}
48
48
49
49
* `children`: Anything that can be rendered with React, such as a piece of JSX (e.g. `<div />` or `<SomeComponent />`), a [Fragment](/reference/react/Fragment) (`<>...</>`), a string or a number, or an array of these.
50
50
51
-
* `domNode`: Some DOM node, such as those returned by `document.getElementById()`. The node must already exist. Passing a different DOM node during an update will cause the portal content to be recreated.
51
+
* `domNode`: Some DOM node, such as those returned by `document.getElementById()`. The node must already exist. Passing a different DOM node during an update will cause the Portal content to be recreated.
52
52
53
-
* **optional** `key`: A unique string or number to be used as the portal's [key.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
53
+
* **optional** `key`: A unique string or number to be used as the Portal's [key.](/learn/rendering-lists#keeping-list-items-in-order-with-key)
54
54
55
55
#### Returns {/*returns*/}
56
56
57
57
`createPortal` returns a React node that can be included into JSX or returned from a React component. If React encounters it in the render output, it will place the provided `children` inside the provided `domNode`.
58
58
59
59
#### Caveats {/*caveats*/}
60
60
61
-
* Events from portals propagate according to the React tree rather than the DOM tree. For example, if you click inside a portal, and the portal is wrapped in `<div onClick>`, that `onClick` handler will fire. If this causes issues, either stop the event propagation from inside the portal, or move the portal itself up in the React tree.
61
+
* Events from Portals propagate according to the React tree rather than the DOM tree. For example, if you click inside a Portal, and the Portal is wrapped in `<div onClick>`, that `onClick` handler will fire. If this causes issues, either stop the event propagation from inside the Portal, or move the Portal itself up in the React tree.
62
62
63
63
---
64
64
@@ -68,7 +68,7 @@ A portal only changes the physical placement of the DOM node. In every other way
68
68
69
69
*Portals* let your components render some of their children into a different place in the DOM. This lets a part of your component "escape" from whatever containers it may be in. For example, a component can display a modal dialog or a tooltip that appears above and outside of the rest of the page.
70
70
71
-
To create a portal, render the result of `createPortal` with <CodeStep step={1}>some JSX</CodeStep> and the <CodeStep step={2}>DOM node where it should go</CodeStep>:
71
+
To create a Portal, render the result of `createPortal` with <CodeStep step={1}>some JSX</CodeStep> and the <CodeStep step={2}>DOM node where it should go</CodeStep>:
72
72
73
73
```js [[1, 8, "<p>This child is placed in the document body.</p>"], [2, 9, "document.body"]]
74
74
import { createPortal } from'react-dom';
@@ -88,7 +88,7 @@ function MyComponent() {
88
88
89
89
React will put the DOM nodes for <CodeStep step={1}>the JSX you passed</CodeStep> inside of the <CodeStep step={2}>DOM node you provided</CodeStep>.
90
90
91
-
Without a portal, the second `<p>` would be placed inside the parent `<div>`, but the portal "teleported" it into the [`document.body`:](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
91
+
Without a Portal, the second `<p>` would be placed inside the parent `<div>`, but the Portal "teleported" it into the [`document.body`:](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
92
92
93
93
<Sandpack>
94
94
@@ -125,15 +125,15 @@ Notice how the second paragraph visually appears outside the parent `<div>` with
125
125
</body>
126
126
```
127
127
128
-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
128
+
A Portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a Portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
129
129
130
130
---
131
131
132
-
### Rendering a modal dialog with a portal {/*rendering-a-modal-dialog-with-a-portal*/}
132
+
### Rendering a modal dialog with a Portal {/*rendering-a-modal-dialog-with-a-portal*/}
133
133
134
-
You can use a portal to create a modal dialog that floats above the rest of the page, even if the component that summons the dialog is inside a container with `overflow: hidden` or other styles that interfere with the dialog.
134
+
You can use a Portal to create a modal dialog that floats above the rest of the page, even if the component that summons the dialog is inside a container with `overflow: hidden` or other styles that interfere with the dialog.
135
135
136
-
In this example, the two containers have styles that disrupt the modal dialog, but the one rendered into a portal is unaffected because, in the DOM, the modal is not contained within the parent JSX elements.
136
+
In this example, the two containers have styles that disrupt the modal dialog, but the one rendered into a Portal is unaffected because, in the DOM, the modal is not contained within the parent JSX elements.
137
137
138
138
<Sandpack>
139
139
@@ -164,7 +164,7 @@ export default function NoPortalExample() {
It's important to make sure that your app is accessible when using portals. For instance, you may need to manage keyboard focus so that the user can move the focus in and out of the portalin a natural way.
241
+
It's important to make sure that your app is accessible when using Portals. For instance, you may need to manage keyboard focus so that the user can move the focus in and out of the Portalin a natural way.
242
242
243
243
Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal) when creating modals. If you use a community package, ensure that it is accessible and follows these guidelines.
244
244
@@ -248,7 +248,7 @@ Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/
248
248
249
249
### Rendering React components into non-React server markup {/*rendering-react-components-into-non-react-server-markup*/}
250
250
251
-
Portals can be useful if your React root is only part of a static or server-rendered page that isn't built with React. For example, if your page is built with a server framework like Rails, you can create areas of interactivity within static areas such as sidebars. Compared with having [multiple separate React roots,](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) portals let you treat the app as a single React tree with shared state even though its parts render to different parts of the DOM.
251
+
Portals can be useful if your React root is only part of a static or server-rendered page that isn't built with React. For example, if your page is built with a server framework like Rails, you can create areas of interactivity within static areas such as sidebars. Compared with having [multiple separate React roots,](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) Portals let you treat the app as a single React tree with shared state even though its parts render to different parts of the DOM.
252
252
253
253
<Sandpack>
254
254
@@ -344,7 +344,7 @@ p {
344
344
345
345
### Rendering React components into non-React DOM nodes {/*rendering-react-components-into-non-react-dom-nodes*/}
346
346
347
-
You can also use a portal to manage the content of a DOM node that's managed outside ofReact. For example, suppose you're integrating with a non-React map widget and you want to render React content inside a popup. To do this, declare a `popupContainer` state variable to store the DOM node you're going to render into:
347
+
You can also use a Portal to manage the content of a DOM node that's managed outside ofReact. For example, suppose you're integrating with a non-React map widget and you want to render React content inside a popup. To do this, declare a `popupContainer` state variable to store the DOM node you're going to render into:
Copy file name to clipboardExpand all lines: src/content/reference/react/Component.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -573,7 +573,7 @@ You should write the `render` method as a pure function, meaning that it should
573
573
574
574
#### Returns {/*render-returns*/}
575
575
576
-
`render` can return any valid React node. This includes React elements such as `<div />`, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
576
+
`render` can return any valid React node. This includes React elements such as `<div />`, strings, numbers, [Portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
*`props`: The `props` argument must either be an object or `null`. If you pass `null`, the cloned element will retain all of the original `element.props`. Otherwise, for every prop in the `props` object, the returned element will "prefer" the value from `props` over the value from `element.props`. The rest of the props will be filled from the original `element.props`. If you pass `props.key` or `props.ref`, they will replace the original ones.
53
53
54
-
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes. If you don't pass any `...children` arguments, the original `element.props.children` will be preserved.
54
+
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [Portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes. If you don't pass any `...children` arguments, the original `element.props.children` will be preserved.
Copy file name to clipboardExpand all lines: src/content/reference/react/createElement.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ function Greeting({ name }) {
42
42
43
43
*`props`: The `props` argument must either be an object or `null`. If you pass `null`, it will be treated the same as an empty object. React will create an element with props matching the `props` you have passed. Note that `ref` and `key` from your `props` object are special and will *not* be available as `element.props.ref` and `element.props.key` on the returned `element`. They will be available as `element.ref` and `element.key`.
44
44
45
-
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
45
+
***optional**`...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [Portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
***Only [JSX tags](/learn/writing-markup-with-jsx) and objects returned by [`createElement`](/reference/react/createElement) are considered to be React elements.** For example, even though a number like `42` is a valid React *node* (and can be returned from a component), it is not a valid React element. Arrays and portals created with [`createPortal`](/reference/react-dom/createPortal) are also *not* considered to be React elements.
50
+
***Only [JSX tags](/learn/writing-markup-with-jsx) and objects returned by [`createElement`](/reference/react/createElement) are considered to be React elements.** For example, even though a number like `42` is a valid React *node* (and can be returned from a component), it is not a valid React element. Arrays and Portals created with [`createPortal`](/reference/react-dom/createPortal) are also *not* considered to be React elements.
51
51
52
52
---
53
53
@@ -109,7 +109,7 @@ function MyComponent() {
109
109
A React node can be:
110
110
111
111
- A React element created like `<div />` or `createElement('div')`
112
-
- A portal created with [`createPortal`](/reference/react-dom/createPortal)
112
+
- A Portal created with [`createPortal`](/reference/react-dom/createPortal)
113
113
- A string
114
114
- A number
115
115
-`true`, `false`, `null`, or `undefined` (which are not displayed)
0 commit comments