React Native provides a built-in RefreshControl component specifically for adding pull-to-refresh functionality to ScrollView and FlatList. Here’s how to use it:

import React, { useState } from 'react';
import { FlatList, RefreshControl } from 'react-native';

function MyFlatList() {
  const [refreshing, setRefreshing] = useState(false);

  const onRefresh = () => {
    setRefreshing(true);
    // fetch data
    // ...
    setRefreshing(false); 
  };
  return (
    <FlatList
      data={yourData}
      renderItem={renderItem}
      refreshControl={
        <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
      }
    />
  );
}

 

Support On Demand!

React Native