Have tried a few different approaches and can't figure out the exact syntax to pass a ref from the parent to the child. Ultimately I'm trying to make it so that I can scroll to beginning onPress of a Child component. Can someone help me figure it out?
Getting error: `scrollViewRef.scrollTo is not a function'
import React, { useRef } from 'react';
import { ScrollView, Button } from 'react-native';
const Parent = () => {
const scrollViewRef = useRef();
const scrollToBeginning = () => {
scrollViewRef.scrollTo({ x: 0, animated: true });
}
return (
<ScrollView
ref={ scrollViewRef }
pagingEnabled
snapToInterval={ width }
horizontal
scrollEventThrottle={16}
scrollEnabled={ true }
>
<Child
scrollToBeginning={ scrollToBeginning }
>
</ScrollView>
)
}
const Child = (props) => {
return (
<Button onPress={ props.scrollToBeginning } title="Scroll To Beginning" />
)
}