H
H
humanIvan2018-08-13 15:59:59
React
humanIvan, 2018-08-13 15:59:59

Why is prevState undefined?

Here is my state

this.state = {
      location: null,
      latitude: null,
      longitude: null,
      carNum: {
        value: null,
        validPassenger: false,
        validTruck: false,
      },
      comment: {
        value: null,
        valid: false,
        validationRules: {
          minLength: 5
        }
      },
      coordinateTrigger: true,
      locationTrigger: true,
    };

Here is my input function
updateInputState = (key, value) => {
    this.setState(prevState => {
      return {
        [key]: {
          ...prevState[key],
          value: value,
          valid: validate(
            value,
            ...prevState[key]
          )
        }
      };
    });
  };

My input
<Textarea
  value={this.state.comment.value}
  onChangeText={val =>
    this.updateInputState("comment", val)
  }
/>

Tell me why it does not see prevState here?
5b7180cb6a830089796363.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question