Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot read property 'getFieldDecorator' of undefined

Tags:

antd

I'm trying to follow the steps provided by Ant design documentation, but I get an error:

TypeError: Cannot read property 'getFieldDecorator' of undefined

import React, { Component } from 'react'
import ReactDom from 'react-dom'
import { Icon, Input, Form} from 'antd'

//
import Header from './layout/Header'

// Import Css
import '../css/Home.css'

class Home extends Component {
    render() {
    const { getFieldDecorator } = this.props.form
    return (
      <div>
        <Form>
        {getFieldDecorator('userName', {
          rules: [{ required: true, message: 'Please input your username!' }],
        })(
          <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" />
        )}
        </Form>
      </div>
    )
  }
}

const WrappedLogin = Form.create()(Home)
ReactDom.render(<WrappedLogin/>, document.getElementById('root'))

export default Home

Did I miss anything?

FYI

antd: 3.1.0 react: 16.2.0 react-dom: 16.2.0

Remark

console.log(this.props.form) // ** return getFieldDecorator: f()

like image 459
Vibol Avatar asked Dec 30 '17 16:12

Vibol


Video Answer


1 Answers

In my case it worked to match the exported identified to the const

export default WrappedLogin
like image 69
gabouy Avatar answered Sep 18 '22 15:09

gabouy