Open Enigama opened 3 years ago
In your example you have a typo with the ref prop.
In example:
ref={(c) => { this._carousel = c; }}
your code:
ref={carousel'}
// what \' pointing to? Where is the declaration of carousel variable?
If you are using this.carousel = React.createRef(); then you need to call it like this.carousel.current.snapToNext(), but if you would follow an example code you wouldn't have any issues using this._carousel.snapToNext().
Can do:
const ref = React.useRef();
const onPress = () => ref.current?.snapToNext?.()
<Carousel
{...}
ref={ref}
/>
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
Is this a bug report, a feature request, or a question?
Hello, I use functional component and when i try to call next slide programmatically like this example: `<Carousel // other props ref={carousel'} />
// methods can then be called this way
onPress={() => { carousel.snapToNext() }}
i haveTypeError: ref.snapToNext is not a function. (In 'ref.snapToNext()', 'ref.snapToNext' is undefined)
so i look what is inside my ref i found{current: {...}}
and inside curent i fond my function `snapToNext.Have you followed the required steps before opening a bug report?
(Check the step you've followed - put an
x
character between the square brackets ([]
).)Have you made sure that it wasn't a React Native bug?
(Write your answer here.) yes