Skip to content

Commit

Permalink
feat: 로딩중일 때 빈화면 대신 로딩중... 문구 띄우는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
feb-dain committed May 22, 2023
1 parent b8b66e3 commit 3868c4f
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/components/main/ProductList.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import { useEffect } from 'react';
import { useRecoilState } from 'recoil';
import { styled } from 'styled-components';
import { PRODUCT_LIST_URL } from '../../constants/url';
import { useSetFetchedData } from '../../hooks/useSetFetchedData';
import { useFetchData } from '../../hooks/useFetchData';
import { productListState } from '../../recoil';
import { Product } from '../../types';
import ProductItem from './ProductItem';

const ProductList = () => {
const [productList, setProductList] = useRecoilState(productListState);

useSetFetchedData<Product[]>(PRODUCT_LIST_URL, setProductList);
const { api, isLoading } = useFetchData<Product[]>(setProductList);

useEffect(() => {
api.get(PRODUCT_LIST_URL);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<S.Wrapper>
{productList.map((product) => (
<ProductItem
key={product.id}
id={product.id}
name={product.name}
price={product.price}
imageUrl={`${process.env.PUBLIC_URL}${product.imageUrl}`}
/>
))}
{isLoading ? (
<p>로딩중...</p>
) : (
productList.map((product) => (
<ProductItem
key={product.id}
id={product.id}
name={product.name}
price={product.price}
imageUrl={`${process.env.PUBLIC_URL}${product.imageUrl}`}
/>
))
)}
</S.Wrapper>
);
};
Expand Down

0 comments on commit 3868c4f

Please sign in to comment.