Nextjs_data 형식 개인 메모

돌리의 하루·2024년 4월 9일
0
import { API_URL } from "../page";

async function getMovie(id: string) {
  const res = await fetch(`${API_URL}/${id}`);
  return res.json();
}

async function getVideo(id: string) {
  const res = await fetch(`${API_URL}/${id}/videos`);
  return res.json();
}
console.log(getVideo);
export default async function MovieDetail({
  params: { id },
}: {
  params: { id: string };
}) {
  const [movie, video] = await Promise.all([getMovie(id), getVideo(id)]);
  return (
    <>
      <h1>{movie.title}</h1>
      <h2>{JSON.stringify(video)}</h2>
    </>
  );
}

video가 json객체형식이었음

[
  {
    iso_639_1: 'en',
    iso_3166_1: 'US',
    name: 'Clip',
    key: 'UJa1zUYegqo',
    site: 'YouTube',
    size: 1080,
    type: 'Clip',
    official: true,
    published_at: '2024-02-16T16:31:54.000Z',
    id: '65d40e001d356301631e68cb'
  },
  {
    iso_639_1: 'en',
    iso_3166_1: 'US',
    name: 'Official Trailer',
    key: 'e1k1PC0TtmE',
    site: 'YouTube',
    size: 1080,
    type: 'Trailer',
    official: true,
    published_at: '2023-11-30T13:02:56.000Z',
    id: '65880cfc5aba326759b95156'
  }
]

movie는 하나의 객체로 이루어져있었고, video는 배열 안에 여러 객체로 이루어져있어서 json.stringify()를 사용하지 않아서 안보였던것.

movie 참고

{
  adult: false,
  backdrop_path: 'https://image.tmdb.org/t/p/w1280/4woSOUD0equAYzvwhWBHIJDCM88.jpg',
  belongs_to_collection: null,
  budget: 0,
  genres: [
    { id: 28, name: 'Action' },
    { id: 27, name: 'Horror' },
    { id: 53, name: 'Thriller' }
  ],
  homepage: '',
  id: 1096197,
  imdb_id: 'tt16253418',
  original_language: 'en',
  original_title: 'No Way Up',
  overview: "Characters from different backgrounds are thrown together when the plane they're travelling on crashes into the Pacific Ocean. A nightmare fight for survival ensues with the air supply running out and dangers creeping in from all sides.",
  popularity: 880.551,
  poster_path: 'https://image.tmdb.org/t/p/w780/hu40Uxp9WtpL34jv3zyWLb5zEVY.jpg',
  production_companies: [
    {
      id: 19638,
      logo_path: 'https://image.tmdb.org/t/p/w300/6R3XtbihMWuDRFnlm4MkpxhmEKf.png',
      name: 'Altitude Film Entertainment',
      origin_country: 'GB'
    },
    {
      id: 290,
      logo_path: 'https://image.tmdb.org/t/p/w300/jrgCuaQsY9ouP5ILZf4Dq4ZOkIX.png',
      name: 'Ingenious Media',
      origin_country: 'GB'
    },
    {
      id: 177401,
      logo_path: 'https://image.tmdb.org/t/p/w300/qGH1GhknZ1P8xv84tDILE8D2Cev.png',
      name: 'Hyprr Films',
      origin_country: 'GB'
    },
    {
      id: 215092,
      logo_path: 'https://image.tmdb.org/t/p/w300null',
      name: 'Sarma Films',
      origin_country: 'GB'
    },
    {
      id: 218231,
      logo_path: 'https://image.tmdb.org/t/p/w300/qI1nnORhDrF2V18KdjitkIOdgN.png',
      name: 'Dimension Studio',
      origin_country: 'GB'
    }
  ],
  production_countries: [ { iso_3166_1: 'GB', name: 'United Kingdom' } ],
  release_date: '2024-01-18',
  revenue: 0,
  runtime: 90,
  spoken_languages: [ { english_name: 'English', iso_639_1: 'en', name: 'English' } ],
  status: 'Released',
  tagline: 'Brace yourself.',
  title: 'No Way Up',
  video: false,
  vote_average: 6.317,
  vote_count: 340
}

또한, use client를 쓰고 있는 컴포넌트가 상위 페이지에 포함된다고 해서 상위 페이지 역시 useclient를 쓸 필요는 없음

profile
진화중인 돌리입니다 :>

0개의 댓글