1The issue that in the first example toggle() is not bound to the correct this.
2
3You can either bind it in the constructor:
4
5constructor(props) {
6 super(props);
7 this.toggle = this.toggle.bind(this);
8 ...
9
10Or use an instance function (OK under some circumstances):
11
12toggle = () => {
13 ...
14}