简体   繁体   English

React portal:在同一个domNode父级内托管多个?

[英]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.

相关问题 在父级内移动同一个类的多个Div - Moving Multiple Divs With Same Class Inside Parent 检索标签内的所有信息:DOMNODE - Retrieved all information inside tags : DOMNODE React 多次将数据从同一个子组件传递给父组件 - React pass data from same child to parent component multiple times React 如何在同一个父组件上显示多个不同来源的组件 - React how to display multiple components of different origin on the same parent component 使用React Portal将子项呈现为父组件的DOM节点 - Use React Portal to render a child into a DOM node of the parent component 如果没有非 React DOM 父级,则无法卸载 React 门户 - 如何在删除父级之前手动卸载门户? - React portal cannot be unmounted without non-react DOM parent - how can I unmount the portal manually before removing the parent? React |当多个孩子同时向父级发送事件时如何更新父级状态 - React |How to Update parent state when multiple children sending event to parent at same time 使用 Javascript 遍历多个父 div(具有相同的类)以访问内部的子 div(相同的类) - Iterate through multiple parent divs (with same class) to access the child divs inside (same class) using Javascript 创建DOMNode以使用React或jQuery传递给Google Maps API - Create DOMNode to pass to google maps API using React or jQuery 在父div上单击时需要在单个div内添加具有相同内容的多个div - Need to add multiple divs with same content inside a single div on a click against the parent div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM