【问题标题】:Element type is invalid (got: undefined) for react-redux componentreact-redux 组件的元素类型无效(得到:未定义)
【发布时间】:2016-10-24 08:41:06
【问题描述】:

我正在尝试为redux-form 创建一个组件。这是我的组件

import React, { PropTypes } from 'react'
import Input from 'react-toolbox'

export const TextField = ({ input, meta: { touched, error }, ...custom }) => (
  <Input
    error={touched && error}
    {...input}
    {...custom}
  />
)

TextField.propTypes = {
  input: PropTypes.object,
  meta: PropTypes.object
}

export default TextField

我还创建了一个index.js 文件以便轻松导入它

import TextField from './TextField'   
export default TextField

那我就这样用

import TextField from 'components/TextField'
import { Field } from 'redux-form'
<form onSubmit={props.handleSubmit(props.loginUser)}>
  <Field type='email' label='Email' name='email' component={TextField} required />
</form>

但是我得到了这个错误

错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。检查TextField的渲染方法。

我又检查了一遍

【问题讨论】:

    标签: reactjs redux redux-form react-toolbox


    【解决方案1】:

    尝试改变:

    import Input from 'react-toolbox'
    

    到:

    import Input from 'react-toolbox/lib/input';
    

    import {Input} from 'react-toolbox';
    

    两者都应该工作

    我认为在你的情况下 Input 是 undefined 像这样导入的

    【讨论】:

    • 坦克很多。我为错过它而感到羞耻。
    猜你喜欢
    • 2019-10-17
    • 2021-03-13
    • 2020-07-22
    • 2021-02-28
    • 2018-11-04
    • 1970-01-01
    • 2021-01-20
    • 2021-10-25
    • 2020-07-13
    相关资源
    最近更新 更多