Skip to content

Conversation

@minjeong517
Copy link

신경 써서 구현한 부분

const fetchMovies = async () => {
  const movies = [];
  for (let i = 1; i <= 2500; i++) {
    movies.push({
      id: i,
      title: `Movie ${i}`,
      description: `Description for Movie ${i}`,
    });
  }
  return movies;
.
(생략)
.
useEffect(() => {
    const loadMovies = async () => {
      setLoading(true);
      await new Promise((resolve) => setTimeout(resolve, 0));
      alert("데이터를 가져오는 중입니다...");
      const data = await fetchMovies();
      setMovies(data);
      setLoading(false);
    };
    loadMovies();
  }, []);
};
  • useEffect 안에서 await fetchMovies()처럼 비동기 방식으로 사용하기 위해 async함수 선언하고 그 안에서 fetchMoviesawait로 호출했습니다.

조건2. ‘fetchMovies’를 호출하여 영화 목록을 화면에 나타내기 전에 Loading 창이 뜨도록 구현하기. (alert 함수를 끝내기 전에 Loading 화면이 보여야 함.)

  • setLoading(true) 직후 await new Promise(resolve => setTimeout(resolve, 0))을 추가해서 alert() 전에 Loading...이 먼저 렌더링이 되도록 했습니다.

Copy link

@gyeongsangseaman gyeongsangseaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 모르는 부분이 있었지만, 작성해주신 PR이 이해하는 데 도움됐습니다 !
특히, 조건2를 구현하는 데 있어 신경 쓰신 게 보였습니다 !
고생하셨습니다 !

Comment on lines +21 to +31
useEffect(() => {
const loadMovies = async () => {
setLoading(true);
await new Promise((resolve) => setTimeout(resolve, 0));
alert("데이터를 가져오는 중입니다...");
const data = await fetchMovies();
setMovies(data);
setLoading(false);
};
loadMovies();
}, []);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

비동기 방식을 구현할 때 다양한 방식을 사용하셨네요 !
여러 기능들을 깔끔하게 사용하신 점이 인상적입니다 !

Comment on lines +43 to +55
const restoreToMain = (movie, listType) => {
if (listType === "watched") {
setWatched((prevWatched) => prevWatched.filter((m) => m.id !== movie.id));
setMovies((prevMovies) =>
[...prevMovies, movie].sort((a, b) => a.id - b.id)
);
} else if (listType === "toWatch") {
setToWatch((prevToWatch) => prevToWatch.filter((m) => m.id !== movie.id));
setMovies((prevMovies) =>
[...prevMovies, movie].sort((a, b) => a.id - b.id)
);
}
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listType을 받아오고 조건에 맞게 각각 다른 처리를 하도록 구현하셨네요 !
위에 moveToWatchedmoveToToWatch도 비슷한 방식으로 구현하는 것도 괜찮았을 것 같아요 !

@martinkang1234
Copy link

pr을 이해하기 쉽게 작성해주셔서 도움이 됐습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants