小编Ara*_*gam的帖子

'&&'运算符用{this.props.children && React.cloneElement(this.props.children,{foo:this.foo})表示什么

我有使用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)

我想了解为什么我们在这里使用'&&'运算符.

reactjs react-router react-native

7
推荐指数
4
解决办法
2万
查看次数

标签 统计

react-native ×1

react-router ×1

reactjs ×1