REACT
리액트 이벤트 연습
Made Project
2020. 5. 9. 01:24
const eventbox = document.querySelector(".phoneclass");
function park1 () {
console.log(eventbox.value);
}
eventbox.addEventListener("keypress",park1);
바닐라 자바스크립트 에드이벤트리스너를 리액트로 바꿔보자.
//onKeyPress
input 태그에서만 쓸수있는 리액트 이벤트 함수
good = () => {
console.log(eventbox.value);
}
<input onKeyPress={this.good}/>
good이라는 함수를 정의해놓고
input태그안에 쓸수있는 이벤트 함수를 넣어놓고 this.good이라는 함수를 넣는다.
키워드를 누를때마다
그러면 this.good이라는 함수가실행된다. 즉 콘솔실행
onkeyPress라는 이벤트함수는 세팅과함꼐 연동일뿐
예문을 보고 이해할것