Rename variables { existing variable : "New variable"}

Darcy Daeseok YU ·2022년 2월 10일
0

오늘은 하나의 함수로 데이터를 가져올려고 한다.

export async function fetchInParallel() {
  const { results: popularData }: { results: IMovie[] } = await (
    await fetch(URL_POPULAR)
  ).json();

  const { results: topRatedData }: { results: IMovie[] } = await (
    await fetch(URL_TOP_RATED)
  ).json();

  const data = { popularData, topRatedData };

  console.log("api test ==========", data);

  return data;
}

데이터 구조가 같다. 변수명도 동일하다.
const { results } = fetch() : popular
const { results } = fetch() : topRated
오류가 발생한다.

해결안은
const { results: popularData }
const { results: topRatedData }

변수명을 재 정의하여 처리하면 된다.

profile
React, React-Native https://darcyu83.netlify.app/

0개의 댓글