我正在使用轮播制作 spfx Web 部件,为此,我正在使用react-elastic-carousal npm-link但是当我尝试使用它时,它给了我一个错误,例如:
Carousel' cannot be used as a JSX component. Its instance type 'ReactElasticCarousel' is not a valid JSX element.
Type 'ReactElasticCarousel' is missing the following properties from type 'ElementClass': render, context, setState, forceUpdate, and 3 more.
我应该为此做什么?
将其添加到您的 tsconfig.json 文件的 compilerOptions 部分中:
“allowSyntheticDefaultImports”:true
因为该组件没有默认导出。
尝试使用以下方法导入Carousel
import * as Carousel from react-elastic-carousel;
尝试使用
require()
导入它并访问组件本身,如下所示:
var Carousel = require("react-responsive-carousel").Carousel;
当我遇到与 react-responsive-carousel
组件同样的问题时,这为我解决了这个问题。