Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.


+10 votes
  changeHandler = (keyName) => {
return (evt) => {


For example if the starting value for a text field is 22 and I backspace once so that the field on the UI reads 2, the value that is grabbed by the evt.target.value is 22 not 2. But If I type a 2 onto the 2 that is already there, the evt.target.value is 2 not 22 as desired...

asked in CSC490_Spring202021 by (8 points)

2 Answers

+2 votes

Use async and await for the method and it will solve your problem :))

answered by (8 points)

Can you explain more clearly how/why this would solve the problem?


I will answer you in a separate comment due to the length.

+2 votes

In most situation, this happens because the data already pushed to others component before your method changeHandler can process it, so what you need to do is create a promise (async, await) like this:
const changeHandler = async (evt) =>{

      await this.props[`set${evt.target.name}`](Number(evt.target.value));
      await this.computeData();


answered by (8 points)