我意识到我写的所有组件都没有使用{this.props.children}.
我倾向于按官方文档在https://facebook.github.io/react/docs/multiple-components.html顶部的方式编写我的组件.
嵌套像这样的组件......
<A>
  <B />
  <C />
</A>
......对这样的作曲有益吗?:
A.js
render() {
    <B />
    <C />
}
假设这是正确的术语,我错过了什么?
Joh*_*ohn 27
在我的应用程序中,我很少使用this.props.children,因为我经常特别知道我想要渲染的孩子.在库中,或者编写为在特定应用程序之外重用的组件,我经常看到它.我认为this.props.children与该用例更相关.
Omr*_*ron 12
我会说当你不知道你想要渲染什么时它会很有用.
例如,你有一个工具提示包装器,让我们说它A是你方案中的组件,你可以使用它来传递不同的内容:
<A>
    <div>Some text...</div>
    <ImageComponent />  // render an image as well
</A>
要么:
<A>
    <div>Only text</div>
</A>
| 归档时间: | 
 | 
| 查看次数: | 10476 次 | 
| 最近记录: |