react 绑定事件 总是默认触发

// if we write like this , code will be fine 
<div className="node-item-container" onClick={()=>this.handleClick()}>
                <div className="corner left-top-conrner">
                    <img src={leftTopCorner}/>
                </div>
                <div className="corner right-top-conrner">
                    <img src={rightTopCorner}/>
                </div>
                <div className="corner left-bottom-conrner">
                    <img src={leftBottomCorner}/>
                </div>
                <div className="corner right-bottom-conrner">
                    <img src={rightBottomCorner}/>
                </div>
                <GlobalProjectContent />
            </div>
// if we write like this, click event will be automatic run in page init

<div className="node-item-container" onClick={this.handleClick()}>
                <div className="corner left-top-conrner">
                    <img src={leftTopCorner}/>
                </div>
                <div className="corner right-top-conrner">
                    <img src={rightTopCorner}/>
                </div>
                <div className="corner left-bottom-conrner">
                    <img src={leftBottomCorner}/>
                </div>
                <div className="corner right-bottom-conrner">
                    <img src={rightBottomCorner}/>
                </div>
                <GlobalProjectContent />
            </div>

// so   we need to select the first one , that will solve the problem

 

posted @ 2018-04-08 15:52  Terre  阅读(563)  评论(0编辑  收藏  举报

风光无限好