I want to pass Boolean State to change className from one component to another component. I tried to pass it through {this.props.isOpen}, but it did not work. How can I pass state value to another component?
Parent component
class Category extends React.Component {
constructor(props) {
super(props);
this.state={ isOpen: false };
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState({ isOpen : !this.state.isOpen })
}
render() {
const categoryContainer = this.state.isOpen ? "isopen" : "";
return(
<div>
<div className="categoryContainer">
<h3>CATEGORIES</h3>
</div>
<button onClick={this.handleClick}>Click</button>
</div>
<div className={categoryStatus} id="category">
<input className="categoryInput" type="text" value="Add Category" placeholder="Add Category" />
<ul>
<li>Greetings</li>
<li>Main Switchboard</li>
<li>Interjections</li>
</ul>
</div>
<Main isOpen={this.state.isOpen} />
</div>
)}
}
Child Component
class Main extends React.Component {
render() {
const botStatus = !this.props.isOpen ? "isopen" : "";
const botInput = !this.props.isOpen ? "isopen" : "";
return (
<div>
<div className={botStatus} id="bot">
<h2>MASTER INTENTS</h2>
<input className={botInput} type="text" value="Add Intent" />
</div>
</div>);
}
}
Thank you for checking my question in advance.