报错如下
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
在网上搜了搜,说是 ES6 模块导出及引入的问题,但检查了好几遍发现模块导出及引入没有问题
原因
引入antd的 TextArea,Option 之类组件时直接从antd引入了,而这些组件是在Input , Select下,不能直接从antd引入的,导致报错异常
import { Modal, Button, Input, Select, Row, Option,TextArea,Col, message } from "antd";
解决方法如下
改为以下方法引入
import { Modal, Button, Input, Select, Row, Col, message } from "antd";
const { TextArea } = Input;
const { Option } = Select;