我有使用react路由器呈现的反应类.我知道React.cloneElement用于将元素从父元素传递给子元素.但是为什么/'&&'运算符对这种语句做了什么:
class Users extends React.Component {
getInitialState() {
return {
page:0
}
},
foo(){
this.setState({'page':1})
}
render() {
return (
<div>
<h2>Users</h2>
{ this.props.children && React.cloneElement(this.props.children, {
foo:this.foo})
</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我想了解为什么我们在这里使用'&&'运算符.