Toggle Showing And Hiding Components In Reactjs
I have been struggling to show/hide components in ReactJs for a couple of days. I am trying to show the ('Write(blocks)' - which needs to be hidden from view by default) and shown
Solution 1:
This is the pattern I would use.
render() {
var hideWriteBlock = (show hide logic);
var hideReadBlock = (show hide logic);
return (
<div className="ProfileSettings">
<SettingsBlock className="Names" label="Name" link="name" hide={hideWriteBlock}>
In the settings component;
render() {
if (this.props.hide) returnnull;
return (
<div>
{this.props.children}
</div>
)
}
I use hide so that I don't have to write if (!this.props.show) return null;.
Post a Comment for "Toggle Showing And Hiding Components In Reactjs"