Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- javascript
- Next.js
- supabase authentication
- xlsx-js-style
- TS
- 이진탐색
- 글또10기x코드트리
- async
- reactnative
- 글또10기
- 배열중복요소제거
- supabase auth
- 스크롤이벤트
- array
- supabase 페이지네이션
- extends
- 슬라이딩윈도우
- 안드로이드빌드에러
- 페이지네이션
- meatadata
- Filter
- react
- app.post
- Spring
- 타입스크립트
- map
- generic
- set
- 상속
- interface
Archives
- Today
- Total
rhanziy
React Native - 아래로 끌어내려서 새로고침 RefreshControl 본문
RefreshControl
스크롤뷰(scrollView)나 리스트뷰(FlatList)에서 상단에서 하단으로 끌어내려서 새로고침할 수 있는 기능이다.
🔽 공식문서 코드
import React from 'react';
import {
RefreshControl,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
} from 'react-native';
const App = () => {
const [refreshing, setRefreshing] = React.useState(false);
const onRefresh = React.useCallback(() => {
setRefreshing(true);
setTimeout(() => {
setRefreshing(false);
}, 2000);
}, []);
return (
<SafeAreaView style={styles.container}>
<ScrollView
contentContainerStyle={styles.scrollView}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}>
<Text>Pull down to see RefreshControl indicator</Text>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
scrollView: {
flex: 1,
backgroundColor: 'pink',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;
사용법 핵간단.
근데 이대로 쓰면 안됨. 데이터 불러오는 api는 보통 useQuery를 이용하니까 useQuery 반환 값 refetch와 isFetched를 사용해
위 코드를 살짝 바꿔줍시다.
const {data, isFetched, refetch} = useQuery커스텀훅();
const [refreshing, setRefreshing] = useState(false);
const onRefresh = () => {
setRefreshing(true);
refetch();
setRefreshing(false);
};
<KeyboardAwareFlatList
{...}
refreshControl={
<RefreshControl onRefresh={onRefresh} refreshing={refreshing} />
}
/>
이러면 아주 잘 새로고침된다. 호호호
🚨🚨비상발생🚨🚨
알고보니 RefreshContrl import 경로가 react-native로 되어있었음. 바꿔주자...
import {RefreshControl} from 'react-native-gesture-handler';
'React Native' 카테고리의 다른 글
React Native - input hidden 처럼 setValue하기(react-hook-form) (1) | 2023.12.01 |
---|---|
React Native - react hook form의 onsubmit에 파라미터로 입력값 넘기기!!! (1) | 2023.12.01 |
React Native - 인풋이 키보드에 가려져요? KeyboardAvoidingView, KeyboardAwareFlatList (2) | 2023.11.23 |
React Native - useInfiniteQuery 파라미터 여러개 넘기기 (0) | 2023.11.23 |
React Native - 무한스크롤 useInfiniteQuery와 FlatList (typescript) (0) | 2023.11.20 |
Comments