diff --git a/src/content/reference/react-dom/createPortal.md b/src/content/reference/react-dom/createPortal.md index 0107c20d3e1..b805a43acd2 100644 --- a/src/content/reference/react-dom/createPortal.md +++ b/src/content/reference/react-dom/createPortal.md @@ -29,13 +29,17 @@ To create a portal, call `createPortal`, passing some JSX, and the DOM node wher ```js import { createPortal } from 'react-dom'; +const portalNode = document.createElement('div') +portalNode.id = 'portal' +document.appendChild(portalNode) + // ...
This child is placed in the parent div.
{createPortal( -This child is placed in the document body.
, - document.body +This child is placed at the end of document body in a portal-specific DOM node.
, + portalNode )}This child is placed in the document body.
"], [2, 9, "document.body"]] +```js [[1, 11, "This child is placed at the end of document body.
"], [2, 12, "portalNode"]] import { createPortal } from 'react-dom'; +const portalNode = document.createElement('div') +portalNode.id = 'portal' +document.appendChild(portalNode) + function MyComponent() { return (This child is placed in the parent div.
{createPortal( -This child is placed in the document body.
, - document.body +This child is placed at the end of document body.
, + portalNode )}` would be placed inside the parent `
` would be placed inside the parent `
This child is placed in the parent div.
{createPortal( -This child is placed in the document body.
, - document.body +This child is placed at the end of document body.
, + portalNode )}