I have the react component below. Why this is not defined when changeNameTwo is called?
See jsbin: http://jsbin.com/nuhedateru/edit?js,output
Then why it works in a typical ES6 Class? See jsbin: http://jsbin.com/kiyijuqiha/edit?js,output
class HelloWorldComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
name : 'yolo'
}
}
changeName = () => {
this.setState({name: 'another yolo'});
}
changeNameTwo() {
this.setState({name: 'another yolo'});
}
render() {
return (
<div>
<h1>Hello {this.props.name}</h1>
<p>Name: {this.state.name}</p>
<button onClick={this.changeName}>Change Name</button>
<button onClick={this.changeNameTwo}>Change Name 2</button>
</div>
);
}
}
React.render(
<HelloWorldComponent name="ES2015/ES6"/>,
document.getElementById('react_example')
);