2017-07-31 52 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 
相关问题