question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call snapToNext in functional component

See original GitHub issue

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 have TypeError: 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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
liplyliecommented, Jul 9, 2021

Can do:

const ref = React.useRef();
const onPress = () => ref.current?.snapToNext?.()

 <Carousel 
  {...}
   ref={ref}
/>
0reactions
dohooocommented, Oct 8, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

this._getCustomDataLength is not a function. #525 - GitHub
Workaround that I'm using is to wrap snapToNext in a function to defer its execution. Looking for a better solution myself.
Read more >
React: Calling functional components as functions
Is it documented somewhere that you can just call a functional component as a plain function? What is the difference between the 2...
Read more >
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
Call a function from a functional component React Native
I have the next problem, trying to call a function from a functional component, like shared in class components. My test code is:...
Read more >
pro tools shortcut mix window
Click on a shortcut category on the left, then hover over a function on the ... Here you can select what components of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found