Skip to content

Conversation

@greenyun2
Copy link
Collaborator

요구사항

기본

  • 자유 게시판 페이지 주소는 “/boards” 입니다.
  • 전체 게시글에서 드롭 다운으로 “최신 순” 또는 “좋아요 순”을 선택해서 정렬을 할 수 있습니다.
  • 게시글 목록 조회 api를 사용하여 베스트 게시글, 게시글을 구현합니다.
  • 게시글 title에 검색어가 일부 포함되면 검색이 됩니다.

심화

  • 반응형으로 보여지는 베스트 게시판 개수를 다르게 설정할때 서버에 보내는 pageSize값을 적절하게 설정합니다.
  • next의 prefetch 기능을 사용해봅니다.

주요 변경사항

스크린샷

멘토에게

  • 미완성입니다ㅜ

@greenyun2 greenyun2 added 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 미완성🫠 죄송합니다.. labels Jun 21, 2024
@greenyun2 greenyun2 changed the title Next.js 최윤석 sprint9 [최윤석] Sprint9 Jun 21, 2024
Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

코드 병합 시 충돌 수정 안된 상태로 그대로 남아있네요~! 확인 부탁드립니다. :)

Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

README.md 파일이라 크게 문제는 없지만, 충돌 제대로 수정하는 습관은 꼭 필요합니다!

export default function BestPost() {
const [bestArticles, setBestArticles] = useState([]);

async function getBestArticles() {
Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

아티클을 조회하는 API 함수를 만들어 분리하고, 이를 가져와서 사용하시는게 좋을 것 같습니다~!
(해당 함수는 API 요청만 처리하면 좋을 것 같아요.)

// 아래 분리하고 이를 가져와서 사용합니다. 
async function getBestArticles(params) {
  // 오류 처리는 필요한 곳에 위임할 수 있도록, 꼭 필요한 경우가 아니면 하지 않습니다.
  const res = await axios.get(`articles?page=${params.page}&pageSize=3&orderBy=${params.orderBy}`);
  return res.data.list ?? [];
}

}

useEffect(() => {
getBestArticles();
Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

응답의 결과로 데이터가 업데이트된 경우에만 고려되고 있는데요.
로딩 및 오류 처리가 가능하도록 다음 상태도 같이 관리하시면 좋을 것 같네요~!

  • isLoading: 데이터 패칭 여부
  • isError: 오류 여부

Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

이러한 기능을 할 수 있는 커스텀 훅을 만들어보는 것도 좋은 것 같습니다.
아래는 사용하는 예시입니다~!
(간단한 예제로 Infinite 케이스는 조금 더 복잡합니다~!)

const { isLoading, isError, data } = useAsync(
  () => getBestArticles(), // fetch 함수
  [] // 의존성 배열
)

</li>
</ul>
<div>
<Image src={signImg} width={40} height={40} alt='로그인 이미지' />
Copy link
Collaborator

Choose a reason for hiding this comment

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

<img/> 태그의 alt 속성은 스크린 리더 사용자나 해당 이미지를 볼 수 없는 사람에게 제공되는 대체 텍스트입니다~!
유의미한 텍스트를 넣어주시는게 좋아요. (이 경우는 로그인하기 등이 될 수 있을 것 같네요.)

Comment on lines +10 to +24
const [articles, setArticles] = useState([]);

async function getArticles() {
try {
const res = await axios.get("/articles?page=1&pageSize=6&orderBy=recent");
const nextArticles = res.data.list ?? [];
setArticles(nextArticles);
} catch (error) {
console.error(error);
}
}

useEffect(() => {
getArticles();
}, []);
Copy link
Collaborator

Choose a reason for hiding this comment

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

아티크를 가져오는 코드도 위에 코멘트 드린 것과 동일하게 개선해보시면 좋을 것 같습니다.

getArticles();
}, []);

console.log(articles);
Copy link
Collaborator

Choose a reason for hiding this comment

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

불필요한 콘솔은 제거해 주세요~ :)


export default function Document() {
return (
<Html lang="en">
Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

언어는 서비스 대상 국가의 언어인 ko로 하시는게 더 적절할 것 같습니다~! :)

export default function App({ Component, pageProps }) {
return (
<>
<Header />
Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

각 페이지 별로 Layout을 가져와서 사용하는 형태도 있습니다~!
(페이지마다 레이아웃을 별개로 가져갈 수 있어, 기획/디자인 변경에 유연하게 대응 가능하면서도 공통으로 가져갈 수 있습니다.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

충돌 수정해 주세요~!!

Copy link
Collaborator

@hoody-jellybean hoody-jellybean Jun 22, 2024

Choose a reason for hiding this comment

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

여기도 코드 충돌 남아있습니다!

Copy link
Collaborator

@hoody-jellybean hoody-jellybean left a comment

Choose a reason for hiding this comment

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

이번 파트 첫 위클리 과제네요! 고생 많으셨습니다. 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Path alias 적용해보시는 것 좋네요! 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Axios에서 제공해주는 인터셉터 활용해보시는 것 좋습니다! 👍

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

Labels

매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 미완성🫠 죄송합니다..

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants