React에서는 기본 동작을 막기 휘애 false리턴을 사용할 수 없다. 반드시 명시적으로 preventDefault를 호출해야 한다.
<!-- 원래는 이렇게 했다. --><ahref="#"onclick="console.log('Clicked.'); return false">
Click
</a>
functionActionLink(){functionhandleClick(e){// 합성 이벤트
e.preventDefault();
console.log('The link was clicked.');}return(<ahref="#"onClick={handleClick}>
Click me
</a>);}
This
자바스크립트에서 클래스 메소드는 기본적으로 bound되지 않는다.
this.handleClick바인트를 잊은 채 onClick에 전달하면, this는 함수가 실제로 호출될 때 undefined로 취급된다.
일반적으로 onClick={this.handleClick}처럼 ()없이 메소드를 참조하려면, 그 메소드를 bind해야 한다.
댓글
댓글 쓰기