【发布时间】:2018-10-19 02:51:27
【问题描述】:
我在尝试使用 AntD 表单时遇到了这个错误:
Element type is invalid: expected a string (for built-in components)
我做过研究,很多话题都在讨论如何导入/导出组件
但是,我不确定这是否是我的问题。这是我的组件:
**** 注册组件 ****
import React, { Component } from 'react'
/** UI Framework Components **/
import { Button, Form, Icon, Input } from 'antd'
class FormWrapper extends Component {
render() {
const { getFieldDecorator } = this.props.form
return (
<Form layout={'horizontal'}>
<Form.Item>
{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.Item>
</Form>
)
}
}
export const RegistrationForm = Form.create()(FormWrapper)
**** 导入组件 ****
import React, { Component } from 'react'
/** Components **/
import { RegistrationForm } from 'Components/RegistrationForm'
/** UI Framework Components **/
import { Card, Tabs } from 'antd'
/** Styled Components **/
const Wrapper = styled(Card)`
${center()};
width: 500px;
`
const TabPane = Tabs.TabPane
export class LoginRegisterContainer extends Component {
state = {
activeTab: '1'
}
render() {
const { activeTab } = this.state
return (
<Wrapper>
<Tabs defaultActiveKey={activeTab}>
<TabPane tab="Register" key="1">
<RegistrationForm />
</TabPane>
<TabPane tab="Log In" key="2">
<LogIn />
</TabPane>
</Tabs>
</Wrapper>
)
}
}
我可以毫无问题地从库中导入所有组件,但是当尝试使用表单时,就会出现这种情况。
【问题讨论】:
标签: reactjs react-redux antd