在用户输入文本字段时尝试对文本字段进行验证。我想errorText
即时更改属性的状态。
Uncaught TypeError: this.setState is not a function
尝试设置状态时收到错误消息。相关代码如下。
export default class Login extends Component {
constructor(props, context) {
super(props, context);
this.state = {
username: null,
errorCopy: null
};
}
handleChange(e) {
this.setState({errorCopy: 'Generic error copy'});
}
render() {
return(
<TextField
hintText="Username"
value={this.state.username}
onChange={this.handleChange}
errorText={this.state.errorCopy} />
)
}
}