-
Notifications
You must be signed in to change notification settings - Fork 40
[이준희] Sprint8 #255
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 #255
The head ref may contain hidden characters: "React-\uC774\uC900\uD76C-sprint8"
Conversation
…ithub-actions [Fix] delete merged branch github action
…sprint2 [이준희] Sprint2
…-sprint3 [이준희] Sprint3
…-sprint7 [이준희] Sprint7
|
수고 하셨습니다 ! 스프리트 미션 하시느라 정말 수고 많으셨어요. |
| }; | ||
|
|
||
| function AllItems() { | ||
| const [orderBy, setOrderBy] = useState<string>("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.
타입 범위를 좁혀볼까요 ?
| const [orderBy, setOrderBy] = useState<string>("recent"); | |
| const [orderBy, setOrderBy] = useState<"recent" | "like">("recent"); |
위와 같이 유니온 타입으로 설정한다면 더욱 명확한 타입을 전달할 수 있어요 !
| interface BestItemCardProps { | ||
| item: Product; | ||
| } |
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.
(제안) 컴포넌트에서 사용되는 타입들만 선언해볼 수 있어요 !
| interface BestItemCardProps { | |
| item: Product; | |
| } | |
| interface BestItemCardProps { | |
| id: number; | |
| name: string; | |
| price: number; | |
| description?: string; | |
| images: string[]; | |
| favoriteCount?: number; | |
| } |
function BestItemCard({ id, name, price ... }: BestItemCardProps) {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.
그리고 호출부에서는 다음과 같이 사용할 수 있어요 !
<BestItemCard {...product} />| function BestItemCard({ item }: BestItemCardProps) { | ||
| return ( | ||
| <div className="item-card"> | ||
| <Link to={`/items/${item.id}`}> | ||
| <img src={item.images[0]} alt={item.name} className="item-card-img" /> |
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 BestItemCard({ item }: BestItemCardProps) { | |
| return ( | |
| <div className="item-card"> | |
| <Link to={`/items/${item.id}`}> | |
| <img src={item.images[0]} alt={item.name} className="item-card-img" /> | |
| function BestItemCard({ item }: BestItemCardProps) { | |
| const { id, name, images } = item; | |
| return ( | |
| <div className="item-card"> | |
| <Link to={`/items/${item.id}`}> | |
| <img src={item.images[0]} alt={item.name} className="item-card-img" /> |
| if (loading) return <div>댓글을 불러오는 중입니다...</div>; | ||
| if (error) return <div>{error}</div>; |
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.
크으 -! 조건부 처리 잘해놨네요 ! 👍
| interface Comment { | ||
| id: number; | ||
| content: string; | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| writer: { | ||
| id: number; | ||
| image: string; | ||
| nickname: 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.
깔끔한 타입선언 ! 😊👍👍
|
|
||
| function ItemComments() { | ||
| const { productId } = useParams<{ productId: string }>(); | ||
| const [comments, setComments] = useState<Comment[]>([]); |
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.
굳굳~! 👍
| interface ProductDetail { | ||
| id: number; | ||
| name: string; | ||
| description: string; | ||
| price: number; | ||
| createdAt: string; | ||
| favoriteCount: number; | ||
| ownerNickname: string; | ||
| ownerId: number; | ||
| images: string[]; | ||
| tags: 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.
깔끔 -! 합니다 ㅎㅎㅎ 👍👍👍
벌써 적응 하셨군요 ㅎㅎㅎ
| } | ||
|
|
||
| function Pagination({ | ||
| currentPage, | ||
| totalPageNum, | ||
| onPageChange, | ||
| }: PaginationProps) { | ||
| const pageNumbers = []; | ||
| const maxVisiblePages = 5; // 한 번에 표시할 최대 페이지 수 | ||
|
|
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 Pagination({ | |
| currentPage, | |
| totalPageNum, | |
| onPageChange, | |
| }: PaginationProps) { | |
| const pageNumbers = []; | |
| const maxVisiblePages = 5; // 한 번에 표시할 최대 페이지 수 | |
| } | |
| const maxVisiblePages = 5; // 한 번에 표시할 최대 페이지 수 | |
| function Pagination({ | |
| currentPage, | |
| totalPageNum, | |
| onPageChange, | |
| }: PaginationProps) { | |
| const pageNumbers = []; | |
| const response = await axios.post( | ||
| "https://panda-market-api.vercel.app/products", | ||
| formData | ||
| ); | ||
| const itemListResponse: ItemListResponse = response.data; |
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.
다음과 같이 axios에 제네릭을 사용할 수 있어요 ㅎㅎㅎ 😊
| const response = await axios.post( | |
| "https://panda-market-api.vercel.app/products", | |
| formData | |
| ); | |
| const itemListResponse: ItemListResponse = response.data; | |
| const response = await axios.post<ItemListResponse>( | |
| "https://panda-market-api.vercel.app/products", | |
| formData | |
| ); | |
| const itemListResponse = response.data; |
| interface Comment { | ||
| id: number; | ||
| content: string; | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| writer: { | ||
| id: number; | ||
| image: string; | ||
| nickname: 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.
지금 보니까 types.ts에 이미 정의되어있네요 ! 공통 타입을 import하는게 어떨까요 ?
|
수고하셨습니다 준희님 !! 타입스크립트 잘 적응하셨는데요 ?? 굳굳 👍 앞으로의 길 진심으로 승승장구하시길 바라겠습니다 !! 🙇♂️🙇♂️ |
요구사항
기본
심화
멘토에게