简单的 React-multi-carousel 示例失败

Simple React-multi-carousel example fails

我正在尝试 运行 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-carouselnpm i react-multi-carousel。我究竟做错了什么?非常感谢任何帮助。

您需要使用默认导入,因为错误提示 import Carousel from "react-multi-carousel"