이 컴포넌트를 ArticleScreen에서 사용해보세요.
screens/ArticleScreen.tsx
import React from 'react'; import {StyleSheet, ActivityIndicator, FlatList} from 'react-native'; import {RouteProp, useRoute} from '@react-navigation/core'; import {RootStackParamList} from './types'; import {useQuery} from 'react-query'; import {getArticle} from '../api/articles'; import {getComments} from '../api/comments'; import ArticleView from '../components/ArticleView'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; type ArticleScreenRouteProp RouteProp<RootStackParamList, 'Article'>; function () { const {params} <ArticleScreenRouteProp>(); const {id} params; const articleQuery (['article', id], () => (id)); const commentsQuery (['comments', id], () => (id)); const {bottom} = useSafeAreaInsets(); // 둘 중 하나라도 준비되지 않은 데이터가 있으면 스피너 보여주기 if (articleQuery.data commentsQuery.data) { return ( <ActivityIndicator size="large" style={styles.spinner} color="black" /> ); } const {title, body, published_at, user} = articleQuery.data; return ( <FlatList style={styles.flatList} contentContainerStyle={[styles.flatListContent, {paddingBottom: bottom}]} data={commentsQuery.data} renderItem={() => null} keyExtractor={item => item.id.toString()} ListHeaderComponent={ <ArticleView title={title} body={body} publishedAt={published_at} username={user.username} /> } /> ); } const styles StyleSheet. ({ spinner { flex 1, }, flatList: { backgroundColor: 'white', flex: 1, }, flatListContent: { paddingHorizontal: 12, }, }); export default ArticleScreen;