2017-08-15 30 views
0

真的很陌生,我試過看其他例子,但沒有意義,所以任何幫助將非常感謝! 我想要做的是有一個簡單的文本字段和提交按鈕,將電子郵件地址添加到MailChimp活動列表。所以只是一個簡單的(理論上)郵件註冊列表。無法讀取React MailChimp註冊表單中未定義的屬性'setState'

我不斷收到此錯誤: 類型錯誤:無法讀取的不確定 OnChange屬性「的setState」:

onChange(e) { 
14 | var email = e.target.value 
15 | this.setState= this.setState.bind(this); 
16 | this.setState({email}) 
17 | } 
18 | render() { 

我試過結合,我在做這個吧?

+0

要查看全碼:https://stackoverflow.com/questions/45677995/react-mailing-signup-error?noredirect=1#comment78313592_45677995 – Sadie

+0

'的onChange =(E)=> {}'而接下來在問一個問題之前嘗試搜索。 你需要綁定'onChange'而不是'setStae'。 – Andrew

+0

我做了,但沒有任何意義。 – Sadie

回答

0

您不需要綁定setState函數,但需要綁定onChange。你是否在構造函數中初始化包含像ES6這樣的電子郵件的狀態?

this.state = { 
    email : '' 
} 

//bind onChange(e) ===== in constructor > like 
this.onChange = this.onChange.bind(this); 

onChange(e) { 
    var email = e.target.value; 
    this.setState({email} //or try this.setState({email:email}); 
} 
相關問題