How can I change state on click event on the buttons? Now I have error
Uncaught TypeError: this.setState is not a function
I know that I can't use here this.setState but I can't understand where should I make bind
class Popup extends React.Component {
  constructor(props){
    super(props);
    this.state = {opened: false};
  }
  componentDidMount(){
    var popupOpenBtn = document.querySelectorAll('[data-popup]');
    popupOpenBtn.forEach(function(item) {
      item.addEventListener("click", function(){
        this.setState({
          opened: true
        });
      })
    });
  }
 
No comments:
Post a Comment