-
Notifications
You must be signed in to change notification settings - Fork 21
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
[김창희] sprint8 #110
The head ref may contain hidden characters: "React-\uAE40\uCC3D\uD76C-sprint8"
[김창희] sprint8 #110
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.
창희님 이번주차 미션 고생하셨습니다~
반복되는 사항의 경우 한번만 리뷰를 드렸으니 고치실때 다른 부분도 찾아보세요~
url: string; | ||
query?: Record<string, any>; | ||
method?: string; | ||
body?: 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.
P1:
any보다 더 적절한 타입을 쓰면 좋겠네요~
body?: any; | |
body?: BodyInit; |
export const fetchData = async (url, query = {}, method = 'GET', body = null, headers = {}) => { | ||
interface FetchDataOptions { | ||
url: string; | ||
query?: Record<string, 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.
P1:
query도 URLSearchParams
의 값으로 넘기는 것이니 string[][] | Record<string, string>
를 추천드립니다.
const queryString = new URLSearchParams(query).toString(); | ||
let data, error, loading = true; | ||
let data: 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.
P1:
이런경우 generic type을 이용해서 어떤 값이 응답값으로 내려오는지 알 수 있게 해주시는 것을 추천드립니다.
interface FetchDataResult<T> {
data: T;
...
}
export const fetchData = async<T>({...}): Promise<FetchDataResult<T>> => {}
// 사용시
fetchData<UserInfo>()
https://www.typescriptlang.org/ko/docs/handbook/2/generics.html
} | ||
|
||
const AddProduct: React.FC<AddProductProps> = ({ | ||
productImage = '', |
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.
P2:
안쓰는 값인데 확인해보세요~
interface AddProductProps { | ||
productImage: string; | ||
productTitle: string; | ||
productDescription: string; | ||
productPrice: string; | ||
productTags: 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.
P2:
AddProductProps라는 이름이 있으니 내부 속성들은 product를 빼는 것이 가독성에 더 좋을 것 같습니다.
interface AddProductProps { | |
productImage: string; | |
productTitle: string; | |
productDescription: string; | |
productPrice: string; | |
productTags: string[]; | |
} | |
interface AddProductProps { | |
image: string; | |
title: string; | |
description: string; | |
price: string; | |
tags: string[]; | |
} |
import { useState } from "react"; | ||
|
||
interface AddItemSharedData { | ||
productImage: string | 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.
P3:
아래코드도 동일동작합니다.
productImage: string | undefined; | |
productImage?: string; |
@@ -37,12 +53,14 @@ const InquireItem = ({setCommentData, commentData, content, userNickname, userIm | |||
|
|||
const handleDelete = () => { | |||
setIsDropdownOpen(false); | |||
setCommentData(commentData.filter((comment) => comment.content !== content)); | |||
setCommentData(commentData.filter((comment: any) => comment.content !== content)); |
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.
P1:
commentData는 string[]이라고 선언하셨는데 comment는 string으로 선언하면 에러가 나는 이유가 뭘까요?
commnetData 가 string[]이 맞는지 확인해보시면 좋겠습니다.
marginBottom = 0 | ||
}) => { | ||
return ( | ||
<hr style={{ marginTop: marginTop, marginBottom: marginBottom }} className={styles['line']} /> |
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.
P3:
아래 코드도 동일 동작합니다~
<hr style={{ marginTop: marginTop, marginBottom: marginBottom }} className={styles['line']} /> | |
<hr style={{ marginTop, marginBottom }} className={styles['line']} /> |
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.
P2:
가능하면 해당 파일의 any를 지워주세요 🥹🥹
@@ -20,7 +33,7 @@ const AddItem = () => { | |||
setProductDescription, | |||
setProductPrice, | |||
setProductTags | |||
} = useAddItemSharedData(); | |||
} = useAddItemSharedData() as AddItemProps; |
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.
P1:
왜 여기서 as 가 필요할까요?
as 를 지우시고 에러가 안 나는 방향으로 코드를 변경하시는 것을 추천드릴께요~
주요 변경사항
스크린샷
멘토에게
React.FC<interface>
처럼 컴포넌트에 걸어줬는데 잘 쓴지도 모르겠습니다