Careful with syntax! You need a set of parens around the object:
this.setState(({toggle}) => ({toggle: !toggle}))
Even worse, your version won't throw a syntax error because toggle: is interpreted as a label, making it a pretty insidious bug (React should hopefully catch it though).
9
u/geoffgiller8 Mar 18 '19
I love this when using react: this.setState({ toggle: !toggle });