class Card extends Component {
state = {
toggled: false
};
onClick() {
this.setState({ toggled: !this.state.toggled });
}
render() {
return (
<div>
{this.state.toggled && <p>Hello World </p>}
<button onClick={this.onClick}>Toggle Card</button>
</div>
);
}
}
I have a simple button that toggles a state and renders a <p>
tag, I'm getting an error code of
TypeError: Cannot read property 'setState' of undefined
when button is pressed