【发布时间】:2016-01-05 01:02:03
【问题描述】:
在用户在文本字段中输入时尝试对文本字段进行验证。我想即时更改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} />
)
}
}
【问题讨论】:
标签: reactjs material-ui