【问题标题】:React.createElement: type is invalid when using array.map inside a stateless componentReact.createElement:在无状态组件中使用 array.map 时类型无效
【发布时间】:2023-03-10 15:29:02
【问题描述】:

我有以下组件:

import React from "react";
import { Grid, Form } from "semantic-ui-react";

const BasicDetail = ({DetailData}) => {
    return(
        <div>
            <Grid.Row>
                <h3>Basic Details</h3>
                {DetailData.map((form) => {
                     return (
                         <Form.input
                             label={form.label}
                             readOnly={true}
                             defaultValue={form.default}
                            type="text"
                         />
                     )
                 })}
            </Grid.Row>
        </div>
    )
}

BasicDetail.propTypes = {
    DetailData: React.PropTypes.array.isRequired
};

export default BasicDetail;

我在 props 中传递了一个对象数组,但出现以下错误:

warning.js:36 警告:React.createElement:类型无效 -- 期望一个字符串(对于内置组件)或一个类/函数(对于 复合组件)但得到:未定义。您可能忘记导出 你的组件来自它定义的文件。检查渲染方法 BasicDetail.

如果我从它正确呈现的组件中删除 .map 函数。

此错误的原因可能是什么?

【问题讨论】:

    标签: javascript reactjs ecmascript-6


    【解决方案1】:

    Semantic UI React 组件名称以大写字母开头。
    使用Form.Input 而不是Form.input

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2022-05-12
      • 2020-04-25
      • 1970-01-01
      • 2018-07-22
      • 2019-08-19
      • 2021-02-24
      相关资源
      最近更新 更多