2017-07-31 51 views
0

嗨,我遇到了Flow和React問題。在React元素`形式的道具中找不到屬性

我得到這些錯誤,我想擺脫他們。我錯過了什麼,我到處搜索。我明白道具已經失蹤,但我似乎無法找到在哪裏定義它們。

流量:屬性className。在React元素的道具中找不到屬性form

流量:屬性onSubmit。物業在道具找不到陣營元素form

export default class LoginForm extends React.Component { 
    _submitForm: Function; 

    constructor(props?: {}) { 
     super(props); 

     this.state = { 
      form: { 
       email: '', 
       password: '', 
      }, 
      errors: { 
       _form: "", 
       email: "", 
       password: "" 
      } 
     }; 

     this._submitForm = this._submitForm.bind(this); 
    } 

    _handleValues(param: string, value?: string) { 
     let obj = this.state; 

     obj['form'][param] = value; 

     this.setState(obj); 
    } 

    _submitForm(event: Event) { 
     this._clearErrors(event); 

     let form = this.state.form; 

     AxiosQueue 
      .post({ 
       url: LINK.AUTHENTICATE, 
       data: form 
      }) 
      .then(({data}) => { 
       if (!data.success) { 
        return; 
       } 
      }) 
      .catch((response) => { 
       console.error(response); 
      }); 
    } 

    render() { 
     const {errors, form} = this.state; 

     const user = UserStore.getUser(); 
     const formText = FORM_TEXT[user.language || "en_AU"]; 

     return (
      <form className="form-inline" onSubmit={this._submitForm}> 

       {errors._form} 

       <InputEmail id="email" error={errors.email} value={form.email} callback={this._handleValues}/> 
       <InputPassword id="password" error={errors.password} value={form.password} 
           callback={this._handleValues}/> 


       <button type="submit" className="btn btn-default">{formText.LOGIN}</button> 
      </form> 
     ); 
    } 
} 

回答

1

有一個在了Syntex const {errors, form} = this.state;form組件與您的變量名form衝突。解決方法是在this.state中給出其他名稱。像

this.state = { 
    formValidation:{ 
     //Validation properties 
    } 
} 

和消費,這樣就會消除衝突

const {formValidation} = this.state 
相關問題