未定义userData no-undef

时间:2020-10-24 15:14:29

标签: reactjs

这是我第一次使用ReactJS,但我不断收到错误消息

'userData'未定义为un-undef

即使我声明了它。这是我的代码:

class Register extends Component {
    constructor(props) {
        super(props);
        this.state = {
            userData: [],
            fullName: "",
            email: "",
            uname: "",
            pass: ""
        }
    }

    onRegis = () => {
        const { fullName, email, uname, pass } = this.state 
        userData = [{fullName, email, uname, pass}]
        this.setState({
            userData
        })
        console.log("Datanya euy: ", userData)
        // console.log(email, " is ", fullName, "'s email addres with username ", uname, " and password ", pass);
    }
}`

1 个答案:

答案 0 :(得分:1)

您忘记通过userDatavarlet定义变量const

const userData = [{fullName, email, uname, pass}];