I have a horizontal ScrollView
, on which I wanted to have scroll functionality, where onPress
it should scroll to right. I am using functional component.
Below is the snippets from my code:
const scroll = React.createRef();
<TouchableOpacity onPress={()=>{scroll.current.scrollTo({x: 0})}}}>
<ScrollView
horizontal={true}
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.horizontalView}
ref={scroll}
>
<TouchableOpacity onPress={() => {scroll.current.scrollTo({x: 100})}}>
I saw above solution while I was searching for one. But this is giving me error:
Cannot read property 'scrollTo' of null
.
I have been hitting my head for hours, but not able to do it. Please help.