首页 文章

在React元素`form`的道具中找不到属性

提问于
浏览
0

嗨,我遇到Flow和React的问题 .

我收到这些错误,我想摆脱它们 . 我错过了什么我到处搜索 . 我知道道具丢失但似乎无法找到定义它们的位置 .

Flow: property className. Property not found in props of React element form

Flow: property onSubmit. Property not found in props of React element 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 回答

  • 1

    与Syntex const {errors, form} = this.state;form 组件中的变量名称 form 存在冲突 . 解决方案是在 this.state 中给出一些其他名称 . 喜欢

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

    消费以消除冲突

    const {formValidation} = this.state
    

相关问题