따로 가져온 API 하나로 합쳐서 정렬하기
① get 으로 가져온 2개의 데이터 각각 useState에 저장하기!
const [myCommentsList, setMyCommentsList] = useState([]); // get으로 가져온 사용자별 댓글 조회
const [myRepliesList, setMyRepliesList] = useState([]); // get으로 가져온 사용자별 대댓글 조회
② 하나로 합치기
const myCommentsRepliesList = [...myCommentsList, ...myRepliesList]; // 사용자별 댓글 + 대댓글
③ 정렬하기(내림차순)
const sortedLists = myCommentsRepliesList.sort(
(a, b) => new Date(b.createAt) - new Date(a.createAt)
);
'⛵ 항해99 > TIL · WIL ✏️' 카테고리의 다른 글
[TIL] 2023.10.25 - tailwind 조건부 CSS (0) | 2023.10.26 |
---|---|
[TIL] 2023.10.24 - w-full 했는데 옆 div가 찌그러질 때! (0) | 2023.10.26 |
[TIL] 2023.10.21 - useRef(input 파일창 - div 연동) (0) | 2023.10.22 |
[TIL] 2023.10.20 - axios.put(변경사항 바로 적용시키기) (0) | 2023.10.20 |
[TIL] 2023.10.19 - axiosInstance headers(Content-Type) 동적 설정 (0) | 2023.10.20 |