加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – ‘\u0026\u0026’运算符用{this.props.chil

发布时间:2020-12-15 20:18:45 所属栏目:百科 来源:网络整理
导读:我有使用react路由器呈现的反应类.我知道React.cloneElement用于将元素从父元素传递给子元素.但为什么/操作符做这样的陈述: class Users extends React.Component { getInitialState() { return { page:0 } },foo(){ this.setState({'page':1}) } render()
我有使用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)
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读