-
Notifications
You must be signed in to change notification settings - Fork 35
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 #275
The head ref may contain hidden characters: "Next-\uC774\uC2B9\uD604-sprint9"
[이승현] Sprint9 #275
Conversation
…ithub-actions [Fix] delete merged branch github action
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.
- 함수 하나당 한가지 동작만 하도록 고민해보시면, 나중에 재사용하기 편할꺼에요!
- 이미 만들어져있는 함수는 반복해서 만들지 않아도 됩니다 :-) 다만, 처음부터 추출하지 않아도 되고 똑같은 함수를 두번만들어서 쓰는 시점에 미리 만들어둔 함수를 재사용해도 됩니다.
- HTTP request는 항상 resolve만 있는건 아니어서, reject 되었을떄는 어떻게 처리할 수 있을지 고민해보시는것도 도움이 될꺼에요!
- 수고많으셨습니다! :-)
const handleSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
const query = { ...router.query }; | ||
if (e.key === "Enter") { | ||
if (searchKeyword.trim()) { | ||
query.keyword = searchKeyword; | ||
} else { | ||
delete query.keyword; | ||
} | ||
|
||
router.replace({ | ||
pathname: router.pathname, | ||
query: query, | ||
}); | ||
} | ||
}; |
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 handleSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | |
const query = { ...router.query }; | |
if (e.key === "Enter") { | |
if (searchKeyword.trim()) { | |
query.keyword = searchKeyword; | |
} else { | |
delete query.keyword; | |
} | |
router.replace({ | |
pathname: router.pathname, | |
query: query, | |
}); | |
} | |
}; | |
const updateRouterQuery = (query)=>{ | |
router.replace({ | |
pathname: router.pathname, | |
query: query, | |
}); | |
} | |
const handleSearchKeyword = (e: React.KeyboardEvent<HTMLInputElement>) => { | |
const query = { ...router.query }; | |
if (e.key === "Enter") { | |
if (searchKeyword.trim()) { | |
query.keyword = searchKeyword; | |
} else { | |
delete query.keyword; | |
} | |
} | |
updateRouterQuery(query) | |
}; | |
- 함수 하나에 2가지 일을 하고 있어서 2개로 분리하는건 어떨까요?
- 분리하면 검색어를 업데이트 하는 함수, 그리고 라우터 쿼리를 업데이트 하는 함수 이렇게 2개로 나눌 수 있을것같아요.
const dateFormat = (date: Date) => { | ||
const newDate = new Date(date); | ||
const formatDate = `${newDate.getFullYear()}.${String( | ||
newDate.getMonth() + 1 | ||
).padStart(2, "0")}.${String(newDate.getDate()).padStart(2, "0")}`; | ||
return formatDate; | ||
}; |
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.
AllArticles에도 같은 함수가 있는것같아요.
만들어져 있는 함수를 재사용해보는건 어떨까요? :-)
{article.likeCount > 9999 | ||
? 9999 + "+" | ||
: article.likeCount} |
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.
9999 같은 숫자는 의미가 불분명해서
const MAX_COUNT = 9999
처럼 변수에 담아주면 의미 파악하기가 더 쉽습니다 :-)
const getAllArticles = async () => { | ||
let params = `/articles?page=1&pageSize=10&orderBy=${order}`; | ||
if (keyword.trim()) { | ||
params += `&keyword=${encodeURIComponent(keyword)}`; | ||
} | ||
const res = await axios.get<ArticlesResponse>(params); | ||
const articles = res.data; | ||
setArticles(articles.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.
fetch가 무조건 성공한다는 가정으로 만들어진 코드같아요
실패의 경우엔 어떻게 핸들링 할지 try,catch 구문으로 에러 핸들링 코드도 적용해보시면 좋을것같아요!
요구사항
기본
심화
스크린샷
멘토에게