[英]React portal: host multiple inside same domNode parent?
React has recently added Portal feature, effectively ripping a sub-tree of virtual DOM out and placing it elsewhere in physical DOM. React最近添加了Portal功能,有效地将虚拟DOM的子树翻录并将其放置在物理DOM的其他位置。
render() {
// React does *not* create a new div. It renders the children into `domNode`.
// `domNode` is any valid DOM node, regardless of its location in the DOM.
return ReactDOM.createPortal(
this.props.children,
domNode,
);
}
Documentation is not clear if each portal must live in its own domNode
. 如果每个门户必须位于自己的domNode
则文档不清楚 。
NOTE: the current implementation as of 11-Feb-2017 does allow multiple portals hosted inside single domNode
. 注意:截至2017年2月11日的当前实现允许在单个domNode
内托管多个门户。 Here's a fork of original CodePlex demo from React's docs, pushing two portals into one parent node: 这是来自React文档的原始CodePlex演示的分支,将两个门户推送到一个父节点:
https://codepen.io/anon/pen/WXYNpE https://codepen.io/anon/pen/WXYNpE
But is this an implementation quirk, or by design? 但这是一个实现怪癖还是设计?
As you can see in mentioned codepen, multiple Portals are appended to domNode (eg inside this node). 正如您在上面提到的codepen中看到的,多个门户被附加到domNode(例如,在此节点内)。 Personally this implementation do not bother me, and as i understand this is by design and not a quirk . 就个人而言,这个实现不会打扰我,因为据我所知, 这是设计而不是怪癖 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.