-
[13]HTML과 React 이벤트 처리의 차이점dev/Web 2021. 4. 12. 19:05
HTML 이벤트의 이름은 소문자이다.
<button onclick='activeLasers()'>
React에서는 이벤트 이름에 camelCase를 사용한다.
<button onClick={Lasers active}>
HTML에서는 prevent default behavior에 false를 반환할 수 있다.
<a href='#' onclick='console.log("The link was clicked."); return false;' />
React에서는 명시적으로 preventDefault()를 사용한다.
function handleClick(event) { event.preventDefault() console.log('The link was clicked.') }
HTML에서는 이벤트에서 함수를 호출할때 위처럼 ()를 사용하지만 React에서는 ()를 사용하지 않는다.
'dev > Web' 카테고리의 다른 글
[15]이벤트 핸들러 또는 콜백에 매개 변수를 전달하는 방법 (0) 2021.04.12 [14]JSX 콜백에서 메서드 또는 이벤트 핸들러를 바인딩하는 방법 (0) 2021.04.12 [12]setState()의 인수로서 콜백 함수의 목적 (0) 2021.04.12 [11]State를 직접적으로 업데이트 하면 안되는 이유 (0) 2021.04.12 [10]State와 Props의 차이 (0) 2021.04.12