Я пытаюсь воспроизвести пример формы antd в https://github.com/ant-design/ant-design/blob/master/components/form/demo/horizontal-login.md
Замена React.createClass на extends React.Component, но я получаю ошибку Uncaught TypeError: невозможно прочитать свойство getFieldDecorator из undefined
со следующим кодом:
import { Form, Icon, Input, Button } from 'antd';
const FormItem = Form.Item;
export default class HorizontalLoginForm extends React.Component {
constructor(props) {
super(props);
}
handleSubmit(e) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
},
render() {
const { getFieldDecorator } = this.props.form;
return (
<Form inline onSubmit={this.handleSubmit}>
<FormItem>
{getFieldDecorator('userName', {
rules: [{ required: true, message: 'Please input your username!' }],
})(
<Input addonBefore={<Icon type="user" />} placeholder="Username" />
)}
</FormItem>
<FormItem>
{getFieldDecorator('password', {
rules: [{ required: true, message: 'Please input your Password!' }],
})(
<Input addonBefore={<Icon type="lock" />} type="password" placeholder="Password" />
)}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit">Log in</Button>
</FormItem>
</Form>
)
}
}
Похоже, что отсутствующая часть Form.create вызывает проблему, но не знаю, где она подходит, используя механизм расширения.
Как мне это сделать правильно?