Code Reference

RefreshControl

React Native · Reference cheat sheet

RefreshControl

React Native · Reference cheat sheet


📋 Overview

RefreshControl adds pull-to-refresh to ScrollView or FlatList. Drive it with controlled refreshing boolean and onRefresh that loads data then clears the flag.

🔧 Core concepts

  • refreshing — spinner visibility.
  • onRefresh — start async reload.
  • ColorstintColor (iOS), colors (Android).
  • Progress view — Android progressViewOffset.
  • Pair — often with React Query refetch.

💡 Examples

import { useCallback, useState } from "react";
import { FlatList, RefreshControl, Text } from "react-native";

export function Feed({
  items,
  reload,
}: {
  items: { id: string; title: string }[];
  reload: () => Promise<void>;
}) {
  const [refreshing, setRefreshing] = useState(false);

  const onRefresh = useCallback(async () => {
    setRefreshing(true);
    try {
      await reload();
    } finally {
      setRefreshing(false);
    }
  }, [reload]);

  return (
    <FlatList
      data={items}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => <Text>{item.title}</Text>}
      refreshControl={
        <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
      }
    />
  );
}

⚠️ Pitfalls

  • Leaving refreshing true on error—use try/finally.
  • Triggering refresh on mount unintentionally.
  • Nested scrollables fighting the gesture.
  • Not awaiting the fetch before clearing state.

On this page