I can't seem to get react swiper working in my react typescript app. I get the error 'Swiper cannot be used as a JSX component, Type Swiper is missing the following properties from 'Element Class': render, context, setstate, forceUpdate and 3 more.'
I've installed the latest version which is 9.2.0 and tried downgrading versions and also changing the import statement as per the following link https://swiperjs.com/react#usage-with-create-react-app but i'm still unable to get the library imported correctly.
My component is below.
import React from 'react';
import { IMarket } from '../interfaces/IMarket';
import { ISelection } from '../interfaces/ISelection';
import MultiDisplay from './MultiDisplay';
import SingleDisplay from './SingleDisplay';
import MarketStatusCover from './MarketStatusCover';
import Swiper from 'swiper';
import SwiperSlide from 'swiper/react';
import { Pagination, Navigation } from 'swiper';
interface MarketProps {
markets: IMarket[];
marketTypeFilter: string;
}
const swiper = new Swiper('.swiper', {
// configure Swiper to use modules
modules: [Navigation, Pagination],
// Optional parameters
direction: 'vertical',
loop: true,
// If we need pagination
pagination: {
el: '.swiper-pagination',
},
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});
function Market(props: MarketProps) {
const { markets, marketTypeFilter } = props;
console.log(markets);
return (
<>
<Swiper>
{markets && markets.map((market: IMarket, index) => (
<SwiperSlide>
(<MarketStatusCover status={market.marketStatus} description={market.marketStatusDescription} />
{index == 0 && <div className="text-center headerFontColour">{market.placeDescription}</div>}
{market.multiMarketOnOneScreen ?
<MultiDisplay selections={market.selections} />
:
<SingleDisplay selections={market.selections} />
}
)
</SwiperSlide>
))}
</Swiper>
</>
);
}
export default Market;