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

前端 未结 5 1916
悲哀的现实
悲哀的现实 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 12:09

    When && and || are used in this way, they are nicknamed "short circuit operators". In this usage, it can be thought of as a quickie "if (something is true)". So, if this.props.children is not null, it will call React.cloneElement. If it is null, it will not call React.cloneElement.

    Here is a link on the official React documentation, with further reading: https://facebook.github.io/react/docs/conditional-rendering.html#inline-if-with-logical-ampamp-operator

提交回复
热议问题