Skip to content

Conversation

@hyeonjiroh
Copy link
Collaborator

#️⃣ Issue Number

#118



📝 요약(Summary)

PC 사이즈 화면에서 이전 페이지 데이터를 불러올 때의 방식 변경

이전에는 각 페이지의 데이터를 캐싱해서 이전 버튼을 눌렀을 때 현재 페이지의 데이터를 삭제하는 방식으로 이전 페이지의 데이터를 보여줬다.

그런데 이전 페이지의 값을 불러올 때만 캐싱을 사용하는 것이 불필요하다고 판단했다.

그래서 다음 버튼을 눌렀을 때 해당 페이지의 cursor 값(다음 버튼을 눌렀기 때문에 이전 페이지의 corsor 값)을 배열에 저장하고, 이전 버튼을 눌렀을 때 해당 배열에서 이전 페이지의 cursor 값을 찾아 해당 cursor 값을 query로 추가하여 get 리퀘스트 요청을 보내는 방식으로 변경하였다.

불필요하게 배경색 지정한 부분 삭제

body에 midnightBlack으로 배경색이 들어가게 되어서 ListPage와 NotFoundPage에 지정한 배경색을 삭제하였다.



🛠️ PR 유형

어떤 변경 사항이 있나요?

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제


@hyeonjiroh hyeonjiroh self-assigned this Feb 4, 2025
@vercel
Copy link

vercel bot commented Feb 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fandom-k ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 10:23am

@hyeonjiroh hyeonjiroh changed the title refactor: #118/DonationsList의 데이터 불러오는 방식 변경 & 불필요한 배경색 지정 부분 삭제 refactor: #118/DonationsList의 데이터 불러오는 방식 변경 Feb 4, 2025
Copy link
Owner

@yoonc01 yoonc01 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~!

Comment on lines +50 to +52
handleLoad({ cursor: cursorArr[cursorArr.length - 2] });
cursorArr.pop();
setCursorArr(cursorArr);
Copy link
Owner

Choose a reason for hiding this comment

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

cursorArr.pop()으로는 cursorArr의 주소가 바뀌지 않아 setCursorArr(cursorArr)를 했을 때 리렌더링을 유도할 수는 없을 거 같아요!

리렌더링을 유도하지 않았더라도 cursorArr.pop()은 불변성을 훼손하기에 좋지 않은 거 같아요!

https://github.com/reactjs/react-basic?tab=readme-ov-file#state

리액트 컨트리뷰터가 작성한 글인데 state는 불변 데이터인 것이 상태 관리를 더 명확하고 예측 가능하게 한다고 해요!

그리고 위의 history.length > 1 조건처럼 cursor: cursorArr[cursorArr.length - 2] 에도 조건이 필요해 보여요! 그렇지 않으면 cursor=undefined로 전달되어서 멘토링 시간에 봤던 400 에러 발생할 거 같아요! 라고 했는데 잘 동작하네요?

const newCursorArr = cursorArr.length > 1 ? cursorArr.slice(0, cursorArr.length - 1) : [0];
handleLoad({ cursor: newCursorArr[newCursorArr.length - 1] });
setCursorArr(newCursorArr);

혹시 몰라 길이에 대한 처리도 했는데 바로 slice한 값을 넣어도 될 거 같네요!

Copy link
Collaborator Author

@hyeonjiroh hyeonjiroh Feb 4, 2025

Choose a reason for hiding this comment

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

우와 감사합니다! 효준님께서 알려주신 방법으로 수정해봐야겠네요! 400에러가 발생하지 않고 잘 동작한 건 cursorArr의 배열에 0을 초기값으로 넣어줘서인 것 같습니다! 그리고 cursorArr의 길이가 1 이하이면 이전 버튼을 비활성화 시켜서 배열의 길이가 1 미만이 될 일도 없고요! 꼼꼼하게 봐주시고 피드백까지 정성스럽게 남겨주셔서 감사합니다~!

@yoonc01 yoonc01 merged commit b0ba63f into main Feb 4, 2025
3 checks passed
@yoonc01 yoonc01 deleted the refactor/#118/Refactor-DonationList-PC branch February 4, 2025 14:48
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