问题描述
我正在尝试使用react-multi-carousel
的基本用法:
import React from 'react';
import {Carousel} from 'react-multi-carousel';
export function MyComponent(props) {
// ...
return (
<Carousel>
<div>Item 1</div>
<div>Item 2</div>
</Carousel>
);
};
但是我得到Error: Element 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,or you might have mixed up default and named imports. Check the render method of 'MyComponent'.
我已将react-multi-carousel
与npm i react-multi-carousel
一起安装。我究竟做错了什么?任何帮助将不胜感激。
解决方法
您需要使用默认导入,因为错误提示import Carousel from "react-multi-carousel"
。