I am making a pen where when user clicks on hamburger icon (top left), I want it to open the sidebar. I saw a thread on SO explaining how to do it here.
In short, the solution is to do something like this:
isActive:function(value){
return 'btn '+((value===this.state.selected) ?'active':'default');
},
I am trying to do something similar (a little different); here is what I did:
expandSidebar(){
this.setState({active: !this.state.active});
console.log(this.state.active ? "square-left active" : "square-left");
return this.state.active ? "square-left active" : "square-left"
}
...
//different React component
<div className={this.props.expandSidebar}>
...
But it does not work. My goal is to display the sidebar when it is clicked, by adding active class. When I console log it, it returns the right string, "square-left active".
This is the codepen: https://codepen.io/iggPen/pen/BdEJmw
What did I do wrong? I am pretty sure it is returning square-left active, but it is not displaying sidebar.
<SidebarRectangle expandSidebar={this.expandSidebar} />to<SidebarRectangle expandSidebar={this.expandSidebar()} /><SidebarRectangle expandSidebar={this.expandSidebar()} />, everything disappeared.