Toggle Class in React

后端 未结 5 925
误落风尘
误落风尘 2020-12-13 18:27

I\'m using react for a project where I have a menu button.

         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 19:01

    refs is not a DOM element. In order to find a DOM element, you need to use findDOMNode menthod first.

    Do, this

    var node = ReactDOM.findDOMNode(this.refs.btn);
    node.classList.toggle('btn-menu-open');
    

    alternatively, you can use like this (almost actual code)

    this.state.styleCondition = false;
    
    
    
    

    you can then change styleCondition based on your state change conditions.

提交回复
热议问题