class Foo extends React.Component{
constructor( props ){
super( props );
}
handleClick(event){
console.log(this); // 'this' is undefined
}
render(){
return (
<button type="button" onClick={this.handleClick}>
Click Me
</button>
);
}
}
ReactDOM.render(
<Foo />,
document.getElementById("app")
);
I've red about this keyword, but i can't understand why in this case when i click on the button this
is undefined? In this case this
should point to the class Foo
, why it is windows object
? How the context is lost in this case?