title: calculation and changing state inside setstate in reactjs
body: <p>I have two states result which initially set to zero and val initially set to 1.
  In the multiply function, I change the states as followed.</p>
  
  <pre><code>multiply(){
  
      console.log('multiply is clicked');
  
      console.log('numberformed is '+this.state.numberformed);
      this.setState(()=&gt;{
          return{
  
  
            val:this.state.val*this.state.numberformed,
            result:this.state.val,
  
  
          };
  
      });
  
     }
  </code></pre>
  
  <p>Here this.state.numberformed outputs 12 as I checked using console.
  I want the result to be equal to 12 so I first changed val as it is seen in the code but the result still reads 1 which is the initial state of val and not the changed state of val.How should I do this?</p>