Why this code:
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
text: "Hello"
};
this.handleClick = this.handleClick.bind(this)
}
handleClick() {
this.setState({
text: "You clicked!"
});
}
And not
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
text: "Hello"
};
this.handleClick = handleClick() { // Is 'this' refering to the constructor?
this.setState({ // also is 'this' here refering to the constructor?
text: "You clicked!"
});
}
}
Thanks,
Andrej