-
Notifications
You must be signed in to change notification settings - Fork 37
[김승석] Sprint9 #299
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
[김승석] Sprint9 #299
The head ref may contain hidden characters: "Next-\uAE40\uC2B9\uC11D-sprint9"
Conversation
| ? console.log("모바일") | ||
| : isTa && isMount | ||
| ? console.log("타블렛") | ||
| : console.log("피씨"); |
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.
모바일 사이즈 적용 후 새로고침 하면
콘솔에 피씨가 잠깐 적용되는데 이유가 뭘까요,,
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.
useEffect는 초기 렌더링이 이미 시작된 이후에 실행되는 훅입니다.
때문에 원하는 결과를 도출하려면 useEffect() 아래에
if (!isMount) {
return null;
}을 두어 초기 렌더링 중일 때 아무 것도 렌더링하지 않게 해야합니다
kich555
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.
고생하셨습니다 ㅎㅎ
src/pages/boards/index.tsx
Outdated
| export const getServerSideProps = async () => { | ||
| const list = await fetchBoardList(1, 3, "like"); | ||
| return { | ||
| props: { | ||
| list, | ||
| }, | ||
| }; | ||
| }; |
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.
getServerSideProps 같은거 써보시는것도 좋습니다 ㅎ
src/pages/boards/index.tsx
Outdated
| const date = new Date(dateString); | ||
| const year = date.getFullYear(); | ||
| const month = String(date.getMonth() + 1).padStart(2, "0"); | ||
| const day = String(date.getDate()).padStart(2, "0"); |
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.
dayjs()같은 라이브러리를 사용하는게 좀더 편리할거에요
src/pages/boards/index.tsx
Outdated
| <> | ||
| <div className="common_title">베스트 게시글</div> | ||
| <ul className={styles.board_best}> | ||
| {list.length === 0 ? ( |
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.
lodash같은 라이브러리를 사용해보는건 어떤가요?
src/pages/boards/index.tsx
Outdated
| const list = await fetchBoardList(1, 3, "like"); | ||
| const commonList = await fetchBoardList(1, 10, "recent"); |
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.
이런식으로 코드를 작성하면 waterfall이 발생할 것 같아요 Promise.all을 활용해보는건 어떤가요?
src/pages/boards/index.tsx
Outdated
| const fetchData = async () => { | ||
| try { | ||
| const bestResponse = await fetchBoardList(1, 3, "like"); | ||
| const commonResponse = await fetchBoardList(1, 10, order); | ||
|
|
||
| setList(bestResponse); | ||
| setCommonList(commonResponse); | ||
| } catch (error) { | ||
| console.error("데이터 가져오기 실패:", error); | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| fetchData(); | ||
| }, [order]); |
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.
이런식으로 작성하려면 fetchData를 useCallback으로 만들고 useEffect의 의존성 배열에 fetchData를 집어넣어야해요
| const onSearch: React.ChangeEventHandler<HTMLInputElement> = (e) => { | ||
| setSearch(e.target.value); | ||
| }; | ||
|
|
||
| const onSearchEnter: React.KeyboardEventHandler<HTMLInputElement> = (e) => { | ||
| if (e.key === "Enter") { | ||
| setKeyword(search); | ||
| } | ||
| }; |
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.
form과 submit이벤트를 활용하는게 더 시멘틱 해 보이네요
요구사항
기본
심화
멘토에게