Last active
April 3, 2021 13:44
-
-
Save i5ar/2f2f5c063bac1f9d95721b5c925ba8f3 to your computer and use it in GitHub Desktop.
Close/open or change division in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {name} = evt.target; | |
if (name === "isLayouts" || name === "isHousing") { | |
this.setState(s => { | |
const stateKeys = Object.keys(s); | |
const index = stateKeys.indexOf(name); | |
if (index !== -1) stateKeys.splice(index, 1); | |
return stateKeys.map( | |
key => ({ | |
[key]: false | |
})).reduce( | |
(acc, cur) => ({ | |
...acc, | |
[Object.keys(cur)]: cur[Object.keys(cur)] | |
}), | |
{ | |
[name]: !s[name] | |
} | |
); | |
}); | |
} | |
//////////////////////// | |
e( | |
"ul", { | |
className: "mode", | |
style: { | |
display: "flex", | |
flexDirection: "row", | |
listStyleType: "none", | |
margin: 0, | |
padding: 0 | |
} | |
}, | |
e("li", { | |
style: liStyle | |
}, e("button", { | |
style: buttonStyle, | |
type: "button", | |
name: "isLayouts", | |
className: isLayouts ? "pure-button pure-button-active" : "pure-button", | |
onClick: this.handleClick | |
}, "Layouts", | |
)), e("li", { | |
style: liStyle | |
}, | |
e("button", { | |
style: buttonStyle, | |
type: "button", | |
name: "isHousing", | |
className: isHousing ? "pure-button pure-button-active" : "pure-button", | |
onClick: this.handleClick | |
}, "Housing") | |
) | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment