reactrondev / react-native-web-swiper

Swiper-Slider for React-Native and React-Native-Web
213 stars 55 forks source link

Allow `React.Component`s to be functional components (TypeScript) #79

Closed pors closed 1 year ago

pors commented 2 years ago

When using a functional React component for e.g. NextComponent there is a TypeScript mismatch:

No overload matches this call.
  Overload 1 of 2, '(props: SwiperProps | Readonly<SwiperProps>): Swiper', gave the following error.
    Type '() => JSX.Element' is not assignable to type 'ComponentClass<{}, any>'.
      Type '() => Element' provides no match for the signature 'new (props: {}, context?: any): Component<{}, any, any>'.
  Overload 2 of 2, '(props: SwiperProps, context: any): Swiper', gave the following error.
    Type '() => JSX.Element' is not assignable to type 'ComponentClass<{}, any>'.ts(2769)

This TypeScript error disappears when using a class component.

eungwang1 commented 2 years ago

Add to the index.d.ts

export interface SwiperProps { ..., children?: React.ReactNode; }

linuxuser07 commented 2 years ago

Add to the index.d.ts

export interface SwiperProps { ..., children?: React.ReactNode; }

which index.d.ts I don't have one on my project.

so create a class component for it, its the best option for now?

BenStirrup commented 2 years ago

+1 for this feature request

jarvisluong commented 1 year ago

Resolved in #84 (released also as v2.2.4)