-
Notifications
You must be signed in to change notification settings - Fork 26
[김참솔] Sprint7-1 #106
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
[김참솔] Sprint7-1 #106
The head ref may contain hidden characters: "React-\uAE40\uCC38\uC194-sprint8"
Conversation
- export하는 요소가 1개이고 파일 이름과 동일하면 default export - export하는 요소가 2개 이상이고 파일 이름이 추상화 되었다면 named export
|
스프리트 미션 하시느라 수고 많으셨어요. |
|
코드를 정리하면서 아래와 같이 폴더 구조도 변경했는데 잘 나눈 것인지 궁금합니다.
넵넵 FSD와 전통적인 리액트 폴더 구조를 반영하여 잘 나누신 것으로 보입니다 👍👍 |
Component에서 api 요청 함수를 호출하는 로직을 custom hook으로 만들어서 사용한다는 글을 본 적이 있는데요. 위와 같은 폴더 구조를 사용한다면 그런 파일들은 hooks에 들어가야 할까요? 아니면 api에 들어가야 할까요?공통 자원인 경우에는 상위의
|
| class HttpClient { | ||
| constructor({ baseUrl }) { | ||
| this.baseUrl = baseUrl; | ||
| } | ||
|
|
||
| async get(target, params) { | ||
| let url; | ||
| if (this.baseUrl) { | ||
| url = createUrl(this.baseUrl, target, params); | ||
| } else { | ||
| url = target; | ||
| } | ||
|
|
||
| const response = await fetch(url, { method: "GET" }); | ||
| if (!response.ok) { | ||
| throw new Error(`HTTP error (status ${response.status}`); | ||
| } | ||
|
|
||
| const json = await response.json(); | ||
| return json; | ||
| } | ||
| } |
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.
크으 직접 만들어보시는걸 택하셨군요 👍👍
훌륭한 도전입니다.
get에 대해서 잘 작성하셨네요 👍
| favorite: "좋아요순", | ||
| }; | ||
| const ORDER_BY_VALUES = Array.from(Object.keys(ORDER_BY_TITLE)); | ||
| export const ORDER_BY_DEFAULT = "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.
해당 상수는 관련 api 함수에 있어도 좋을 것 같네요 !
현재 위치는 order-by-select.jsx이네요.
"해당 컴포넌트의 기본 값"을 의미한다면 현재 그대로 둬도 좋으나,
"API 통신에 필요한 파라메터의 기본 값"을 의미한다면 api 함수 파일로 옮겨도 되겠어요 😉
|
|
||
| async function fetchProducts({ | ||
| keyword = "", | ||
| page = 1, | ||
| pageSize = 10, | ||
| orderBy = "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.
(이어서) 만약 옮긴다면 다음과 같이 되겠네요 😉
| async function fetchProducts({ | |
| keyword = "", | |
| page = 1, | |
| pageSize = 10, | |
| orderBy = "recent", | |
| const ORDER_BY_DEFAULT = "recent"; | |
| async function fetchProducts({ | |
| keyword = "", | |
| page = 1, | |
| pageSize = 10, | |
| orderBy = ORDER_BY_DEFAULT, |
| const PROFILE_INFO_STYLE = { | ||
| [USER_PROFILE_CARD_SIZE.large]: { | ||
| infoGap: 2, | ||
| fontSize: 14, | ||
| lineHeight: 24, | ||
| cardGap: 16, | ||
| avatarSize: 40, | ||
| }, | ||
| [USER_PROFILE_CARD_SIZE.small]: { | ||
| infoGap: 4, | ||
| fontSize: 12, | ||
| lineHeight: 18, | ||
| cardGap: 8, | ||
| avatarSize: 32, | ||
| }, | ||
| }; |
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.
굿굿 ! 함수를 지우고 객체로 만드셨군요 ! 👍👍👍
function을 실행시키는게 아니라 객체 인덱싱 구조로 변경되었기에 성능도 더 개선되었을거라 사료됩니다. 😊
| const sortedComments = useMemo( | ||
| () => | ||
| comments.sort( | ||
| (a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt) | ||
| ), | ||
| [comments] | ||
| ); |
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.
굿굿 ! 정렬은 자원이 많이 들어갈 수 있지요 👍
메모이제이션을 활용하여 성능을 높이셨군요 👍
|
수고하셨습니다 참솔님 😊 |
요구사항
주요 변경사항
styled-components를 사용하도록 변경했습니다.멘토에게
features폴더를 추가하고 아래에 기능 별 파일들을 모아 두었습니다.features/*/components에는 별도의 파일로 분리했지만 특정 기능에 종속된 component들을 모아 두었습니다.app.jsx와main.jsx는 root component 및 entry point 이므로src바로 아래에 위치했습니다.hooks에 들어가야 할까요? 아니면api에 들어가야 할까요?