[React] 이벤트 핸들러에서 this 사용하기
1. 생성자에서 핸들러에 this를 바인딩 class MyComponent extends React.Component { constructor() { this.state = { someState, }; this.myMethod = this.myMethod.bind(this); // this 바인딩 } myMethod() { this.setState({someState: 'another state'}); } render() { return ( ); } } 2. 핸들러 등록과 함께 this를 바인딩 class MyComponent extends React.Component { constructor() { this.state = { someState, }; } myMethod() { this.setState(..
프론트엔드
2020. 10. 27. 00:18
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total