-
Notifications
You must be signed in to change notification settings - Fork 51
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
[김진우] Week19 #554
base: part3-김진우
Are you sure you want to change the base?
The head ref may contain hidden characters: "part3-\uAE40\uC9C4\uC6B0-week19"
[김진우] Week19 #554
Conversation
const getCurrentUser = async () => { | ||
try { | ||
const res = await instance.get(USERS_ENDPOINT, { | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
}, | ||
}); | ||
const { data } = res; | ||
return data; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; |
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.
를 포함한 getLinks , getFolders 는 컴포넌트 밖으로 꺼내는게 좋아요. 컴포넌트가 리랜더링할 때 마다 해당 함수를 매번 새로 생성해야하니 이런식으로 코드를 작성하면 성능이 떨어지게됩니다. 코드 유지보수성 측면에서도 좋지 않구요
let links; | ||
if (folderId === ALL_LINK_NAME) { | ||
try { | ||
const res = await instance.get(`/links`, { | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
}, | ||
}); | ||
const { data } = res; | ||
links = data; | ||
setFilteredLinks(links); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} else if (typeof folderId === "number") { | ||
try { | ||
const res = await instance.get(`/folders/${folderId}/links`, { | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
}, | ||
}); | ||
const { data } = res; | ||
links = data; | ||
setFilteredLinks(links); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
return links; |
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 url = folderId === ALL_LINK_NAME ? link:forlders/${forderId}/link
하면 fetch 반복이 줄겠네요!
- setFiltered는 파생상태니 지양하자고 했었죠?
const addFolder = async () => { | ||
instance.post( | ||
`/folders`, | ||
{ | ||
name: addFolderName, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${getAccessToken()}`, | ||
}, | ||
} | ||
); | ||
}; |
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.
addFolderName 변수를 암묵적인자로 받으려고 하니 컴퍼넌트안에 해당함수가 들어가있는거라고 판단했어요.
명시적인자로 밖에서 받을 수 있게하면, 해당 함수을 컴퍼넌트바깥으로 보낼 수 있어요.
const signup = async () => { | ||
const res = await instance.post(`${SIGNUP_ENDPOINT}`, { | ||
email: watch("email"), | ||
password: watch("password"), | ||
}); | ||
const accessToken = res?.data.accessToken; | ||
setAccessToken(accessToken); | ||
res.status === 200 && router.push("/folder"); | ||
}; | ||
|
||
const signupMutation = useMutation({ | ||
mutationFn: signup, | ||
}); | ||
|
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.
- email, password를 명시적 인자오 받았으면 컴퍼넌트 밖으로 뺄 수 있음
- set...함수를 fetch 함수 내부에서 호출하는게 아니라, useMutation의 onSuccess 콜백 안에서 호출해야합나자
요구사항
기본
주요 변경사항
멘토에게