TIL 47. React Native로 Movie App 만들기

isk·2023년 1월 6일
0

TIL

목록 보기
45/122
post-custom-banner

무비 앱을 만들었다.

Now Playing 부분

const [nowPlayingData, setNowPlaying] = useState([]);
const getNowPlayingMovies = async () => {
    const response = await fetch(
      "https://api.themoviedb.org/3/movie/now_playing?api_key=<<API_KEY 부분>>&language=en-US&page=1"
    ).then((res) => res.json());
    setNowPlaying(response.results);
  };

Top Rated 부분

const [topRatedData, setTopRated] = useState([]);
const getTopRatedMovies = async () => {
    const response = await fetch(
      "https://api.themoviedb.org/3/movie/now_playing?api_key=<<API_KEY 부분>>&language=en-US&page=1"
    ).then((res) => res.json());
    setTopRated(response.results);
  };

Up Coming 부분

const [upComingData, setUpComing] = useState([]);
const getUpComingMovies = async () => {
    const response = await fetch(
      "https://api.themoviedb.org/3/movie/now_playing?api_key=<<API_KEY 부분>>&language=en-US&page=1"
    ).then((res) => res.json());
    setUpComing(response.results);
  };

모든 데이터를 한 번에 받아오기

const getData = async () => {
    await Promise.all([
      getNowPlayingMovies(),
      getTopRatedMovies(),
      getUpComingMovies(),
    ]);
    setIsLoading(false);
  };
post-custom-banner

0개의 댓글