-
Notifications
You must be signed in to change notification settings - Fork 37
[최성락] Sprint8 #277
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
The head ref may contain hidden characters: "React-\uCD5C\uC131\uB77D-sprint8"
[최성락] Sprint8 #277
Changes from all commits
de581c2
fd68cfc
d883dfd
6e67112
d79f0fd
3679fb2
add9ad0
e3b2b02
85c271a
88284df
52532ca
01befbd
c3cfeca
e3d02d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import React from "react"; | ||
| import { Outlet } from "react-router-dom"; | ||
|
|
||
| const App: React.FC = () => { | ||
| return <Outlet />; | ||
| }; | ||
|
|
||
| export default App; |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { fetchProducts } from "../../domains/product/index"; | ||
| import { useCallback, useEffect, useState } from "react"; | ||
| import { HttpException } from "../../utils/exceptions"; | ||
| import ItemCard from "../ui/Item/ItemCard"; | ||
| import "./AllProductsSection.css"; | ||
| import { SortOption, Product } from "../../domains/product/index"; | ||
| import { getPageLimit } from "../../utils/getPageLimit"; | ||
| import { debounce } from "../../utils/debounce"; | ||
|
|
||
| interface AllProductsSectionProps { | ||
| sortOption: SortOption; | ||
| } | ||
|
|
||
| function AllProductsSection({ sortOption }: AllProductsSectionProps) { | ||
| const [items, setItems] = useState<Product[]>([]); | ||
| const [pageSize, setPageSize] = useState(getPageLimit(window.innerWidth, "all")); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const getProducts = async (limit: number, sort: SortOption): Promise<void> => { | ||
| try { | ||
| const { list } = await fetchProducts(sort, limit); | ||
| setItems(list); | ||
| } catch (error) { | ||
| console.error(error); | ||
| const message = error instanceof Error ? error.message : "알 수 없는 오류가 발생했습니다"; | ||
| setError(message); | ||
| } | ||
| }; | ||
|
|
||
| const handleResize = useCallback(() => { | ||
| const newPageSize = getPageLimit(window.innerWidth, "all"); | ||
| if (newPageSize !== pageSize) { | ||
| setPageSize(newPageSize); | ||
| } | ||
| }, [pageSize]); | ||
|
|
||
| useEffect(() => { | ||
| const debounceResize = debounce(handleResize, 300); | ||
| window.addEventListener("resize", debounceResize); | ||
| return () => window.removeEventListener("resize", debounceResize); | ||
| }, [handleResize]); | ||
|
Comment on lines
+37
to
+41
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resize 될때 처리한 부분도 나쁘지 않게 잘 된것같아요ㅎㅎ! 왜냐하면 값이 바뀌었을때만 요청이 날아갈꺼거든요! |
||
|
|
||
| useEffect(() => { | ||
| if (pageSize !== null) { | ||
| getProducts(pageSize, sortOption); | ||
| } | ||
| }, [sortOption, pageSize]); | ||
|
|
||
| if (error) { | ||
| return <div>오류: {error}</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <section className="all-products"> | ||
| <div className="all-products-list"> | ||
| {items.map((item) => ( | ||
| <ItemCard key={item.id} item={item} /> | ||
| ))} | ||
| </div> | ||
| </section> | ||
|
Comment on lines
+54
to
+60
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 깔끔하게 잘 구현하셨네요ㅋㅋ |
||
| ); | ||
| } | ||
|
|
||
| export default AllProductsSection; | ||
This file was deleted.
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.
이정도로 예외처리 해도 충분하긴 해요!
아마 느끼셨겠지만 이런 부분들이 매우 많이 사용될꺼에요.
그래서 이걸 추상화하고 공통으로 묶어서 사용하려고 사람들이 많이 시도해왔는데, react-query라는 라이브러리를 한번 사용해보시면 좋을것같아요ㅎㅎ!
이거 같이 멘토링에서 해보시져...!