-
Notifications
You must be signed in to change notification settings - Fork 45
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
[조혜진] Week15 #483
The head ref may contain hidden characters: "part3-\uC870\uD61C\uC9C4-week15"
[조혜진] Week15 #483
Conversation
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.
혜진님 15주차 미션도 수고많으셨습니다 👍🏽
시간 추가로 내셔서 리액트로 바꾸지 못한 부분도 바꿔보시고
기존 리뷰에 코멘트 달아드렸던 부분들이나 멘토링 때 알려드린 것들도 꼼꼼히 적용해보시면 좋을 것 같아요!
{folderList && | ||
folderList.data.map((folder: Link) => ( | ||
{folders && | ||
folders.map((folder: any) => ( |
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.
any 말고 유효한 타입으로 정의해주세요! 이 부분은 충분히 넣어줄 수 있는 부분 같아보이네요 👀
const folderData = useFetch(`${BASE_URL}folders/${folderId}`); | ||
|
||
useEffect(() => { | ||
if (folderData && folderData.data && folderData.data.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.
옵셔널체이닝(?
) 사용해서 개선할 수 있겠네요
if (folderData && folderData.data && folderData.data.length > 0) { | |
if (folderData?.data?.length > 0) { |
@@ -21,78 +23,211 @@ export interface Folder extends Card { | |||
}; | |||
} | |||
|
|||
export function useSharedData() { | |||
const [data, setData] = useState<Card[]>([]); | |||
export function useFolderInfo(folderId: string) { |
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.
보통 하나의 파일 안에 하나의 커스텀훅을 둡니다
파일 별로 찢어보면 좋을 것 같아요
if (linksData) { | ||
const parsedData = linksData.data.map((link: Card) => ({ | ||
if (folderData && folderData.data) { | ||
const parsedData = folderData.data.map((link: any) => ({ |
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.
여기도 any 대신 타입 넣어주세요!
showDot: false, | ||
showStar: false, |
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.
멘토링 때 설명드린대로 boolean 형 변수네이밍 변경해보면 좋을 것 같습니다!
|
||
const linksData = useFetch(`${BASE_URL}users/1/links?folderId=${folderId}`); | ||
export function useUserData() { | ||
const [userData, setUserData] = useState<any>(null); |
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.
전반적으로 타입 정의하는 곳에 any 가 많군요! 혜진님 충분히 하실 수 있을 만한 부분이라고 생각되니 개선 부탁드려요!
try { | ||
const accessToken = localStorage.getItem("accessToken"); | ||
if (!accessToken) return; | ||
|
||
const response = await fetch(`${BASE_URL}links`, { | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to fetch user 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.
이 부분 + 144~146라인까지 반복되는 코드들을 어떻게 개선할 수 있을지도 고민해보시면 좋을 것 같습니당
return data; | ||
} catch (error) { | ||
throw new Error(`Error login: `); | ||
throw new Error(`Error login`); |
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.
문자열 내부에서 변수 활용이 없는 경우는 백틱(`) 대신 작은 따옴표(') 를 사용합니다
|
||
export const useFetchUser = () => { | ||
const [data, setData] = useState<User | null>(null); | ||
const [loading, setLoading] = useState(true); |
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.
초기값은 false 로 두는게 자연스러운 것 같아요!
// folderId가 문자열 | undefined일 경우 첫번째 문자열을 선택 | ||
const folderIdString = | ||
typeof folderId === "string" ? folderId : Array.isArray(folderId) ? folderId[0] : undefined; |
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.
query parameter 로 사용되는 forderId 가 명확하게 string 인 경우 저는 타입 단언으로 처리하기도 합니다
(사용처에서 forderId as string
과 같은 식으로 작성)
요구사항
기본
심화
주요 변경사항
스크린샷
멘토에게