Answer the question
In order to leave comments, you need to log in
How to more elegantly change multiple state values per click?
There is a drop-down menu that opens on click. There are four of them. And four boolean state values for each of them.
state = {
sidebarOpenMenu1: false,
sidebarOpenMenu2: false,
sidebarOpenMenu3: false,
sidebarOpenMenu4: false,
}
handleSidebarOpenMenu1 = () => {
this.setState({
sidebarOpenMenu1: !this.state.sidebarOpenMenu1,
sidebarOpenMenu2: false,
sidebarOpenMenu3: false,
sidebarOpenMenu4: false,
})
}
handleSidebarOpenMenu2 = () => {
this.setState({
sidebarOpenMenu1: false,
sidebarOpenMenu2: !this.state.sidebarOpenMenu2,
sidebarOpenMenu3: false,
sidebarOpenMenu4: false,
})
}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question