feat: add article for react portals (#33715)

pull/27052/head^2
Karthik Rao 2019-06-24 19:15:42 +05:30 committed by Tom
parent 251b857d12
commit 4392455ff7
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
---
title: Portals
---
## Portals
Portals were introduced with React 16.0. Portal provides a mechanism for a component to render its children in a DOM node that is outside the DOM hierarchy of parent component. In other words, a component that returns a portal from its render method can cause its children to be rendered as children of a completely different DOM node in the DOM tree. As a result, the position of the portal will be different in DOM tree versus the React tree.
A portal can be created like so
```javascript
ReactDOM.createPortal(child, container)
```
Here `child` is a element, string, or fragment and `container` is a DOM element.
A detailed explanation with example can be found in the official documentation. The difference in postion of the portal can be observed in the browser's dev tools by comparing the 'Elements' and 'React' tabs.
#### More Information
[React Portals](https://reactjs.org/docs/portals.html)