I'm using react for a project where I have a menu button.
<a ref=btn href=# className=btn-menu show-on-small><i></i></a>
And a Sidenav component like:
<Sidenav ref=menu />
And I wrote the following code to toggle the menu:
class Header extends React.Component {
constructor(props){
super(props);
this.toggleSidenav = this.toggleSidenav.bind(this);
}
render() {
return (
<div className=header>
<i className=border hide-on-small-and-down></i>
<div className=container>
<a ref=btn href=# className=btn-menu show-on-small><i></i></a>
<Menu className=menu hide-on-small-and-down/>
<Sidenav />
</div>
</div>
)
}
toggleSidenav() {
this.refs.btn.classList.toggle('btn-menu-open');
}
componentDidMount() {
this.refs.btn.addEventListener('click', this.toggleSidenav);
}
componentWillUnmount() {
this.refs.btn.removeEventListener('click', this.toggleSidenav);
}
}
The thing is that this.refs.sidenav
is not a DOM element and I cant add a class on him.
Can someone explain me how to toggle class on the Sidenav
component like I do on my button?