Movie App01(async-await, component화, propType)

o:kcalb·2023년 12월 21일
0

React

목록 보기
14/29
post-thumbnail
import logo from './logo.svg';
import temp from './img.png';
import './App.css';
import Movie from './Movie.js';
import { useState, useEffect } from 'react';

function App() {
  const [loading, setLoading] = useState(true);
  const [movies, setMovies] = useState([]);
  const getMovies = async() => {
      const json = await(
        await fetch(
          'https://yts.mx/api/v2/list_movies.json?minimum_rating=8.8'
        )
      ).json();
    setMovies(json.data.movies);
    setLoading(false);
  }

  useEffect(() => {
    getMovies();
  }, []);

  return <div>
    {loading ? <h1>Loading...</h1> : <ol>{movies.map((item) => 
      <Movie 
        key={item.id}
        coverImg={item.medium_cover_image}
        title={item.title}
        summary={item.summary}
        genres={item.genres}
      />
    )}</ol>}
  </div>
}

export default App;
import propTypes from "prop-types";

function Movie({coverImg, title, summary, genres}){
    return <li>
        <div>
            <img src={coverImg} alt={title} />
        </div>
        <strong>{title}</strong>
        <p>{summary}</p>
        <ul>
        {genres.map((genresItem) => 
            <li key={genresItem}>{genresItem}</li>
        )}
        </ul>
    </li>
}

Movie.propTypes = {
    coverImg: propTypes.string.isRequired,
    title: propTypes.string.isRequired,
    summary: propTypes.string.isRequired,
    genres: propTypes.arrayOf(propTypes.string).isRequired
}

export default Movie;

profile
모든 피드백 받습니다 😊

1개의 댓글

comment-user-thumbnail
2024년 2월 13일

Wrapped in the comfort of my favorite blanket, I embarked on a cinematic journey through the captivating selection of films, eager to immerse myself in a world of storytelling wonders. Tonight's movie choice held the promise of an unforgettable experience, inviting me to explore the depths of human emotion and imagination. With each scene, I https://kinogo-la.org/ was drawn into the intricate tapestry of the story, feeling every moment as if I were a part of it. From the bustling streets of a bustling city to the tranquil beauty of nature's landscapes, I marveled at the richness of the settings and the depth of the characters. In those immersive moments, I found myself transported to a realm where anything was possible, captivated by the magic of cinema.

답글 달기

관련 채용 정보