How would I add the name const to the second setState method? In order to increment currentCompany I must include the prevState. When I attempt to add the name const it does not work.
const name = company.word;
this.setState({ name });
this.setState(prevState => ({
  currentCompany: (prevState.currentCompany + 1)
}));
Thank you for your help :)
this.setState(prevState => ({
  name: company.word,
  currentCompany: (prevState.currentCompany + 1)
}));
                        You can write it like this also:
this.setState({ 
    name ,
    currentCompany: this.state.currentCompany + 1
})
Multiple setState within a function is not a good idea, try to do all the calculation then use setState once after that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With