state = { showSomething: false } toogleSomething = () => { const holder = this.state.showSomething; this.setState({showSomething: !holder});
//Holder holds the previous value so that the next time you call the function it will be updated with the other new state value and therefore toggle. }
No comments:
Post a Comment