Skip to content

Instantly share code, notes, and snippets.

@i5ar
Last active April 3, 2021 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i5ar/2f2f5c063bac1f9d95721b5c925ba8f3 to your computer and use it in GitHub Desktop.
Save i5ar/2f2f5c063bac1f9d95721b5c925ba8f3 to your computer and use it in GitHub Desktop.
Close/open or change division in React
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