Open bitttttten opened 4 years ago
I also have such problem in my code
I was trying to use it like
const carouselRef = useRef<CarouselStatic<CarouselPage[]>>();
<Carousel ref={carouselRef} />
^^^^^^^^^^^ - shows warning
I also have problem too. I trying with pagination
const ref= useRef<any>();
//Here works
<Carousel ref={ref}/>
// Here not works
<Pagination carouselRef={ref} />
I try other ways like:
const ref= useRef<CarouselStatic<any>>();
const ref= useRef<Flatlist<any>>();
But unsuccefully
I'm getting the same issue, I needed a workout for this at the moment which was to just declare any
on the ref. Awful but I needed the build to pass.
const carouselRef: any = useRef(null)
//
carouselRef.current.snapToItem(index);
const ref = useRef() ref.current.anything is undefined
what to do 😭
Hey folks.
const carouselRef = useRef<Carousel<Item>>(null);
This way worked for me. I had to initialize ref
with null
value, and the warning is gone.
I hope this can be usefull for you.
Hey folks.
const carouselRef = useRef<Carousel<Item>>(null);
This way worked for me. I had to initialize
ref
withnull
value, and the warning is gone.I hope this can be usefull for you.
Sorry but what is Item
meaning here? Can you let me know please 🙏
@cuongn265 Item
is the type that you want to use in carousel list, can be a TypeScript class, interface or type.
Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2
Can anyone help me ? I tried everything above, but nothing worked.
try to edit like this.
const carouselRef = useRef<Carousel<any>>(null);
carouselRef.current?.snapToNext
I got this working by doing:
const carousel = useRef<Carousel<Item> & CarouselStatic<Item>>(null)
Same problem here, but mine is triggering in Pagination
component
Full component code for refference:
@hugolcouto Did you ever solve this? Having the same issue.
const carousel = useRef<Carousel<typeof renderItem>>()
where renderItem is your render function.
Btw, @hugolcouto what's your theme and font ? aha
This library is unmaintained. It's in your best interested to stop using it entirely.
Switch to dohooo/react-native-reanimated-carousel
Is this a bug report, a feature request, or a question?
Bug report.
Have you followed the required steps before opening a bug report?
Have you made sure that it wasn't a React Native bug?
Yes
Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?
TypeScript related.
Is the bug reproductible in a production environment (not a debug one)?
Yes
Environment
Expected Behavior
That TypeScript does not error when using useRef.
Actual Behavior
TypeScript warns that refs are not compatible.
Steps to Reproduce
Will error:
I also tried typing the useRef with
CarouselStatic
but this didn't help.I see that I can also do:
Although I am not sure the typings are correct?