我刚开始学习本机反应,我的输入字段有问题。 我没有任何编译错误但是当我执行并按下按钮时出现错误:
Undefined不是对象('this.state.username')
这可能与糟糕的国家管理有关。
这是我的代码:
Name received: dog
The sentence entered is 5 characters long
感谢您的帮助。
答案 0 :(得分:0)
你要么这样做
_userSignup() {
const { username } = this.state;
const { password } = this.state;
}
或者这样做
_userSignup() {
const username = this.state.username;
const password = this.state.password;
}
Learn more about ES6 destructuring feature或check out what Dan has to say about it。