당겨서 새로 고침과 더 불러오기
RefreshControl을 사용해 onRefresh를 구현하여 사용자가 아래로 당겨 데이터를 다시 불러오게 하고, onEndReached로 결과의 다음 페이지를 가져옵니다.
당겨서 새로 고침과 더 불러오기은(는) CoddyKit의 무료 React Native Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 React Native Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Pull-to-Refresh?
Pull-to-refresh is a mobile-native gesture where the user pulls the list downward to trigger a data reload. It signals to the app that new content should be fetched from the server. React Native's FlatList has built-in support for this gesture through the onRefresh and refreshing props.
The refreshing and onRefresh Props
FlatList's pull-to-refresh requires two props: refreshing (a boolean that shows or hides the spinner) and onRefresh (a callback that runs your data-fetch logic). Set refreshing to true when the fetch starts and back to false when it completes.
const [refreshing, setRefreshing] = useState(false);
const onRefresh = async () => {
setRefreshing(true);
await fetchData();
setRefreshing(false);
};
<FlatList
data={items}
renderItem={renderItem}
keyExtractor={(item) => item.id}
refreshing={refreshing}
onRefresh={onRefresh}
/>Using RefreshControl for Custom Styling
For more control over the spinner's appearance, use the refreshControl prop with a RefreshControl component. This lets you set the spinner's tintColor (iOS) and colors (Android), and even add a custom progressViewOffset for apps with fixed headers.
import { RefreshControl } from 'react-native';
<FlatList
data={items}
renderItem={renderItem}
keyExtractor={(item) => item.id}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={onRefresh}
tintColor='#6200ee'
colors={['#6200ee', '#03dac5']}
/>
}
/>Infinite Scroll with onEndReached
Infinite scroll (load more / pagination) fetches additional data when the user approaches the bottom of the list. FlatList fires the onEndReached callback when the user scrolls within onEndReachedThreshold of the end. A threshold of 0.5 triggers the callback when the user is halfway to the end.
const [page, setPage] = useState(1);
const [items, setItems] = useState([]);
const loadMore = async () => {
const newItems = await fetchPage(page + 1);
setItems(prev => [...prev, ...newItems]);
setPage(prev => prev + 1);
};
<FlatList
data={items}
renderItem={renderItem}
keyExtractor={(item) => item.id}
onEndReached={loadMore}
onEndReachedThreshold={0.5}
/>Preventing Duplicate Load Calls
onEndReached can fire multiple times in quick succession as the user scrolls. Guard against duplicate fetches with a loading flag. Check the flag at the start of your load function and return early if a fetch is already in progress. Reset the flag once the data is loaded.
const [loadingMore, setLoadingMore] = useState(false);
const loadMore = async () => {
if (loadingMore) return; // guard against duplicates
setLoadingMore(true);
const newItems = await fetchPage(page + 1);
setItems(prev => [...prev, ...newItems]);
setPage(prev => prev + 1);
setLoadingMore(false);
};Footer Spinner for Load More
Show an ActivityIndicator in the ListFooterComponent while the next page is loading. Hide it when all pages are loaded. This gives users a visual cue that more content is coming and prevents them from repeatedly scrolling to try to load more when it is already loading.
const renderFooter = () => {
if (!loadingMore) return null;
return <ActivityIndicator style={{ padding: 16 }} />;
};
<FlatList
data={items}
renderItem={renderItem}
keyExtractor={(item) => item.id}
onEndReached={loadMore}
onEndReachedThreshold={0.5}
ListFooterComponent={renderFooter}
/>Detecting End of Data
Keep a hasMore boolean in state. When your API returns fewer items than the page size, you know there are no more pages. Set hasMore to false and guard the loadMore function with this check. Also update the footer to show an 'End of list' message instead of a spinner.
const [hasMore, setHasMore] = useState(true);
const loadMore = async () => {
if (loadingMore || !hasMore) return;
setLoadingMore(true);
const newItems = await fetchPage(page + 1);
if (newItems.length < PAGE_SIZE) setHasMore(false);
setItems(prev => [...prev, ...newItems]);
setPage(prev => prev + 1);
setLoadingMore(false);
};Combining Refresh and Load More
Pull-to-refresh and load more can coexist in the same FlatList. On refresh, reset the page to 1, clear the existing items, fetch the first page, and reset hasMore to true. The two flows are independent and use separate loading states so they do not interfere with each other.
const onRefresh = async () => {
setRefreshing(true);
setPage(1);
setHasMore(true);
const freshData = await fetchPage(1);
setItems(freshData);
setRefreshing(false);
};onEndReachedThreshold Best Practices
The onEndReachedThreshold value is a fraction of the visible list height, not a pixel value. Setting it to 0.2 triggers loading when 20% of the list content remains visible below the screen. A higher value starts loading earlier for slower APIs; a lower value is better for fast API responses.
// Trigger load more when 20% of list remains
<FlatList
onEndReached={loadMore}
onEndReachedThreshold={0.2}
/>Scroll Position After Refresh
After a refresh replaces the data array, FlatList may retain the old scroll position, making the new content invisible. Call flatListRef.current.scrollToOffset({ offset: 0, animated: true }) after setting fresh data to bring the list back to the top for a polished user experience.
const flatListRef = useRef(null);
const onRefresh = async () => {
setRefreshing(true);
const freshData = await fetchPage(1);
setItems(freshData);
flatListRef.current?.scrollToOffset({ offset: 0, animated: true });
setRefreshing(false);
};Testing Pull-to-Refresh on Emulator
On iOS Simulator, pull-to-refresh works with a trackpad two-finger swipe down on the list. On Android Emulator, click and drag down from a list item. On a physical device, the gesture is natural. Always test both platforms because iOS uses a native spinner while Android uses its own Material-style indicator.
Quick Check
Test your understanding of pull-to-refresh and infinite scroll from this lesson.
Lesson Recap
In this lesson you learned: use the refreshing and onRefresh props to implement pull-to-refresh, use onEndReached with onEndReachedThreshold for infinite scroll, and guard loadMore with a loading flag to prevent duplicate API calls. Next up we explore SectionList for grouped data with headers.
자주 묻는 질문
“당겨서 새로 고침과 더 불러오기” 강의는 무료인가요?
네 — “당겨서 새로 고침과 더 불러오기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 React Native Academy 강의 전체를 잠금 해제할 수 있습니다. React Native Academy 강의에는 총 4개의 강의가 포함되어 있습니다.
“당겨서 새로 고침과 더 불러오기”에서 뭘 배우나요?
RefreshControl을 사용해 onRefresh를 구현하여 사용자가 아래로 당겨 데이터를 다시 불러오게 하고, onEndReached로 결과의 다음 페이지를 가져옵니다. 브라우저에서 직접 실행하는 실습 코드로 React Native Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
React Native Academy을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 React Native Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“당겨서 새로 고침과 더 불러오기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 React Native Academy 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 React Native Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.