Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call snapTo if I use functional component? #294

Open
intmainreturn00 opened this issue Oct 2, 2019 · 2 comments
Open

How to call snapTo if I use functional component? #294

intmainreturn00 opened this issue Oct 2, 2019 · 2 comments

Comments

@intmainreturn00
Copy link

Sample here shows how to use snapTo from a class-based component for starting the animation by a button click.

Since Hook's, it's more tempting to use functional components with state, but in functional components, we can't use refs for obtaining instance. Is there any other way to use snapTo for Interactable.View inside functional component? If so, could you please provide some sample?

Thanks in advance and thanks for a great work!

@manuel-grondona
Copy link

You could useRef, something like this worked for me:

const interactableRef = useRef(null)

handlePress = () => {
interactableRef.current.snapTo({ x: 0 })
}

<Interactable.View
    ref={interactableRef}
   .......
>
.........
</Interactable.View>

@ShivamJoker
Copy link

You can also use
containerRef.current.snapTo({index: 1});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants