// Create a reference to the ScrollView
const scrollViewRef = useRef(null);
// Scroll handler
const onScrollToTop = () => {
if (scrollViewRef.current) {
scrollViewRef.current.scrollTo({ x: 0, y: 0, animated: true }); //animated: true for smooth scrolling
}
};
// Render the ScrollView and Button
<ScrollView ref={scrollViewRef}>
</ScrollView>
<TouchableOpacity
onPress={onScrollToTop}
>
<Text>{“Go to Top”></Text>
</TouchableOpacity>
Work with our skilled React Native developers to accelerate your project and boost its performance.
Hire React Native Developers