【问题标题】:How to embed elements in React Components, make it like the Container如何在 React 组件中嵌入元素,使其像 Container
【发布时间】:2016-12-19 00:18:33
【问题描述】:

我想要这样构建组件:

class MyContainer extends React.Component {
    render(){

        return <div width="1000">{xxx }</div>
    }
}

并且可以这样使用:

<MyContainer><xxx></xxx></MyContainer>

【问题讨论】:

  • 你的问题是?
  • 这只会给已经很复杂的系统增加不必要的复杂性。如果您将 &lt;div&gt; 嵌入到组件本身中,则更具可读性和可追溯性

标签: html reactjs jsx


【解决方案1】:

我认为您正在寻找 this.props.children。这将进入容器组件。容器标签中的任何嵌套元素都会被渲染到 this.props.children 中。

【讨论】:

    猜你喜欢
    • 2019-12-18
    • 2017-10-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 2019-12-20
    • 2012-01-30
    • 1970-01-01
    • 2018-09-03
    相关资源
    最近更新 更多