更改状态后 TextInput 值未更新?

TextInput value is not updated after changing state?

        <TextInput
            label={'Please enter your email'}
            onChangeText={text => this.onChangeText(text)}
            style={textInputStyle}
            value={this.state.testEmail}
        />

检查我用来处理文本的函数,我在其中附加了一些虚拟文本,但它没有得到反映。

onChangeText = (text, id) => {
    this.setState((previousState) => ({
                testEmail:
                text+'test'
            }
        )
    )
}

这是构造函数,

constructor(props) {
    super(props);
    this.state = {
        testEmail: '',
    };
}

试试这个:

<TextInput
  label={'Please enter your email'}
  onChangeText={this.onChangeText}
  style={textInputStyle}
  value={this.state.testEmail}
/>

onChangeText = text => {
  this.setState({
    testEmail: `${text}test`
  });
}

小吃样品 here.

shouldComponentUpdate 此方法匿名调用,导致不更新 TextInput