here is my code:
import React from 'react';
export default class MovieCard extends React.Component {
constructor(props) {
super(props);
this.state = { content: 'test' };
}
changer = () => {
this.setState({ content: 'changed' });
};
// changer() {
// this.setState({ content: 'changed' });
// }
render() {
return (
<div>
<h1>{this.state.content}</h1>
<button onClick={this.changer}>click me to change</button>
</div>
);
}
}
The regular function (I commented it out) should do the same but it does not work, while the arrow function work and change the state of the h1 element.
why is that? what is the problem?