forked from woowacourse/react-shopping-cart-prod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import * as S from './ProductItemList.styles'; | ||
import ProductItem from 'components/Product/ProductItem'; | ||
import LoadingSkeleton from 'components/Product/ProductItem/LoadingSkeleton'; | ||
import { useGet } from 'hooks/useGet'; | ||
import { Product } from 'types'; | ||
import { getProductList } from 'api/requests'; | ||
import { productListSelector } from 'recoil/productList'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
const ProductItemList = () => { | ||
const { data, isLoading } = useGet<Product[]>(getProductList); | ||
|
||
const loading = Array.from({ length: 16 }).map((_, idx) => ( | ||
<LoadingSkeleton key={idx} /> | ||
)); | ||
const data = useRecoilValue(productListSelector); | ||
|
||
const fetchedProductList = | ||
data && | ||
data.map((product) => <ProductItem key={product.id} product={product} />); | ||
|
||
return ( | ||
<> | ||
<S.ProductListWrapper> | ||
{isLoading ? loading : fetchedProductList} | ||
</S.ProductListWrapper> | ||
</> | ||
); | ||
return <S.ProductListWrapper>{fetchedProductList}</S.ProductListWrapper>; | ||
}; | ||
|
||
export default ProductItemList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getProductList } from 'api/requests'; | ||
import { atom, selector } from 'recoil'; | ||
import { Product } from 'types'; | ||
import { serverAtom } from './server'; | ||
|
||
export const productListSelector = atom<Product[]>({ | ||
key: 'productList', | ||
default: selector({ | ||
key: 'initalProductList', | ||
get: async ({ get }) => { | ||
const server = get(serverAtom); | ||
const data = await getProductList(server); | ||
return data; | ||
}, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters