0

I am trying to update the set the states onClick method

constructor(props) {
  super(props);
  this.state = {
     from: 'a',
     to: 'b',
  };
  this.previousClick = this.previousClick.bind(this);
}
previousClick() {    
  var currDate = '1';
  let toDate = '2';
  console.log(currDate, toDate);
  this.setState = ({
    from: this.currDate,
    to: this.toDate,
  });
  console.log(this.state);
}

It is still showing the 'a' and 'b'

Icepickle
  • 12,689
  • 3
  • 34
  • 48
Bhawna
  • 705
  • 2
  • 11
  • 28
  • As the duplicate mentions, `setState` doesn't apply at once, you could provide a callback function that get's called after your state was applied. Also, when you post a question, please do the least bit of effort of indenting your code properly ;) – Icepickle Feb 13 '18 at 11:47
  • 1
    You are also incorrectly using `setState`. – Chris Feb 13 '18 at 11:49

0 Answers0