ReactComponent 不能用作 spfx tsx webpart 中的 JSX 组件

问题描述 投票:0回答:3

我正在使用轮播制作 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.

我应该为此做什么?

reactjs typescript sharepoint jsx spfx
3个回答
1
投票

将其添加到您的 tsconfig.json 文件的 compilerOptions 部分中:
“allowSyntheticDefaultImports”:true
因为该组件没有默认导出。


0
投票

尝试使用以下方法导入Carousel

import * as Carousel from react-elastic-carousel;

0
投票

尝试使用

require()
导入它并访问组件本身,如下所示:

var Carousel = require("react-responsive-carousel").Carousel;
当我遇到与 

react-responsive-carousel

 
组件同样的问题时,这为我解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.