Skip to main content
100%

Autoscroll to last item in React-Native flat list

✓ Published0🌍 Public
AAnsonT
Last edited Jul 25, 2023
Created on Jul 25, 2023

This example demonstrates an auto-scrolling React Native `FlatList` that automatically jumps to the bottom whenever new data arrives. The component tracks the list’s total content height via `onContentSizeChange` and stores it in state. Inside a `useEffect`, it calls `scrollToOffset` with that stored height whenever the `data` prop or content height changes, ensuring the view snaps to the last item. It uses the `useRef` hook to hold a reference to the `FlatList` instance and relies on React’s state and effect lifecycle to trigger the scroll behavior without manual user interaction.

AI-generated description

Similar vizzes