-
Notifications
You must be signed in to change notification settings - Fork 0
8회차 과제 - 김민정 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
8회차 과제 - 김민정 #10
Conversation
gyeongsangseaman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 모르는 부분이 있었지만, 작성해주신 PR이 이해하는 데 도움됐습니다 !
특히, 조건2를 구현하는 데 있어 신경 쓰신 게 보였습니다 !
고생하셨습니다 !
| useEffect(() => { | ||
| const loadMovies = async () => { | ||
| setLoading(true); | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| alert("데이터를 가져오는 중입니다..."); | ||
| const data = await fetchMovies(); | ||
| setMovies(data); | ||
| setLoading(false); | ||
| }; | ||
| loadMovies(); | ||
| }, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
비동기 방식을 구현할 때 다양한 방식을 사용하셨네요 !
여러 기능들을 깔끔하게 사용하신 점이 인상적입니다 !
| 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) | ||
| ); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listType을 받아오고 조건에 맞게 각각 다른 처리를 하도록 구현하셨네요 !
위에 moveToWatched와 moveToToWatch도 비슷한 방식으로 구현하는 것도 괜찮았을 것 같아요 !
|
pr을 이해하기 쉽게 작성해주셔서 도움이 됐습니다 |
신경 써서 구현한 부분
useEffect안에서await fetchMovies()처럼 비동기 방식으로 사용하기 위해async함수 선언하고 그 안에서fetchMovies를await로 호출했습니다.setLoading(true)직후await new Promise(resolve => setTimeout(resolve, 0))을 추가해서alert()전에 Loading...이 먼저 렌더링이 되도록 했습니다.