Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
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 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

ksw_devlog

TIL 11주 4일차-react native project 본문

TIL

TIL 11주 4일차-react native project

kimcoach 2023. 1. 12. 23:43

usequery를 이용하여 사용하는 api 연결

import styled from '@emotion/native';
import { useQuery, useQueryClient } from 'react-query';
import MusicalCard from '../components/Musicals/MusicalCard';
import Loading from './Loading';
import { useState } from 'react';
import { RefreshControl } from 'react-native';
import { getBoxOfficeWeek } from '../api';
import { filterOnlyMusicals } from '../util';

// 모든 공연 페이지
export default function Musicals() {
  const [refreshing, setRefreshing] = useState(false);
  const queryClient = useQueryClient();
  const { data: boxOfficeWeekData, isLoading } = useQuery(
    'WeeklyMusical',
    getBoxOfficeWeek
  );
  const filteredBoxOfficeMonth = filterOnlyMusicals(
    boxOfficeWeekData?.boxofs?.boxof
  );

  const onRefresh = async () => {
    setRefreshing(true);
    await queryClient.refetchQueries(['WeeklyMusical']);
    setRefreshing(false);
  };

  if (isLoading) {
    return <Loading />;
  }

  return (
    <Container
      refreshControl={
        <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
      }
    >
      <MusicalCard data={filteredBoxOfficeMonth} />
    </Container>
  );
}

const Container = styled.ScrollView``;

 

 

 

 

'TIL' 카테고리의 다른 글

WIL 11주차  (0) 2023.01.16
TIL 11주 5일차 - React Native project 회고  (0) 2023.01.13
TIL 11주 3일차-react native project  (0) 2023.01.11
TIL 11주 2일차-react native project  (0) 2023.01.10
TIL 11주 1일차-react native project  (0) 2023.01.09