React.props.children 无限期

我仍然不太确定父母如何反应/孩子们。

我有一个叫做的组件
quiz

, 这拉我的组件
quizBody



<div classname="quizContainer">
<h1>{this.props.quizName}</h1>
<quizbody disabled="{this.state.disabled}" handleenteredvalue="{this.handleEnteredValue}" onenter="{this.onEnter}" quizname="{this.props.quizName}" start="{this.startQuiz}" time="{this.props.time}" youwon="{this.state.youWon}"></quizbody>
</div>


因此,我建议测验将是父母 quizBody? 但是当我打电话的时候
this.props.children

在任何文件中。 我不确定吗?
如果有必要,您可以放置​​更多代码,但只是让孩子们如何工作 react.
已邀请:

三叔

赞同来自:

props.children

安装在当前项目的内容上。


<outer>
{"hello!"}
</outer>


在这种情况下
Outer

' s
this.props.children

- 这是
"hello"

.

在你的例子中
this.props.children

- 这是
undefined


QuizBody

, 因为你创造了
QuizBody

没有内容。

三叔

赞同来自:

鉴于以下组件结构:


<parent>
<children></children>
<children></children>
</parent>


父组件 2 孩子们 /孩子/.

其中一个用途 React.children 如下:


class Parent extends React.Component {
render// {
console.log/this.props.children/;
return /
<div>
{ this.props.children }
</div>
/
}
}

const Child = // => <div>Hello</div>

const Family = // => <parent>
<child></child>
<child></child>
</parent>

ReactDOM.render/<family></family>,
document.getElementById/'app'//



<script src="[url=https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>]https://cdnjs.cloudflare.com/a ... gt%3B[/url]
<script src="[url=https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>]https://cdnjs.cloudflare.com/a ... gt%3B[/url]
<div id="app"></div>

君笑尘

赞同来自:

退房
https://jsfiddle.net/jmxgp5pp/
, 了解它是如何工作的 'children'.


var Parent = React.createClass/{
render: function// {
return /
<div>
{this.props.children.map/child =&gt; <div>
Child: {child}
</div>/}
<span>I'm not a child</span>
</div>
/;
}
}/;

var Child = React.createClass/{
render: function// {
return /
<span> I'm {this.props.name} </span>
/;
}
}/;

ReactDOM.render/
<parent>
<child name="one"></child>
<child name="two"></child>
</parent>
,
document.getElementById/'container'/
/;

要回复问题请先登录注册