Autobinding
class SayHello extends React.Component {
constructor(props) {
super(props);
// This line is important!
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
alert('Hello!');
}
render( {
// 'this.handleClick'이 바운드되있기 때문에,
// event handler로써 handleClick 사용 가능
return (
<button onClick={this.handleClick}>
Say Hello
</button>
)
})
}Summary
Last updated
Was this helpful?