Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+11 votes
  changeHandler = (keyName) => {
return (evt) => {
  this.props[`set${keyName}`](Number(evt.target.value));
  this.computeData();
};

};

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 (1 point)

2 Answers

+2 votes

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

answered by (1 point)
+2

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

+2

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 (1 point)
...