What does '&&' operator indicate with { this.props.children && React.cloneElement(this.props.children, { foo:this.foo})

前端 未结 5 1917
悲哀的现实
悲哀的现实 2020-12-15 11:22

I have react class that is rendered using react router. I understand that React.cloneElement is used to pass elements from parent to child. But why/what does the \'&&

5条回答
  •  旧巷少年郎
    2020-12-15 11:50

    It's Short circuit evaluation

    (if this part is true) && (this part will execute)
    

    And it shorthand of:

    if(condition){
       (this part will execute)
    }
    

提交回复
热议问题