我有使用 react 路由器渲染的 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>
)
}
}
我想了解为什么我们在这里使用“&&”运算符。
请您参考如下方法:
这是短路评估
(if this part is true) && (this part will execute)
它的简写是:
if(condition){
(this part will execute)
}






