From b05a44eb0a07d8c9d532dab63bbe6d37f6f930bc Mon Sep 17 00:00:00 2001 From: Laktionov Anton Date: Thu, 4 Jun 2026 19:05:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/list/product/index.jsx | 45 ++------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/components/list/product/index.jsx b/src/components/list/product/index.jsx index db22f0c..78c44ae 100644 --- a/src/components/list/product/index.jsx +++ b/src/components/list/product/index.jsx @@ -1,50 +1,9 @@ -import React from 'react' import styles from './index.module.scss' - import ProductCard from '../../card/product' +import { useProducts } from '../../../hooks/useProducts' const ProductList = () => { - const [products, setProducts] = React.useState([]) - const [loading, setLoading] = React.useState(true) - const [error, setError] = React.useState(null) - - React.useEffect(() => { - let cancelled = false - - const getProducts = async () => { - try { - setLoading(true) - setError(null) - - const response = await fetch('http://localhost:8000/products') - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) - } - - const data = await response.json() - - if (!cancelled) { - setProducts(data) - } - } catch (err) { - if (!cancelled) { - setError(err.message) - setProducts([]) - } - } finally { - if (!cancelled) { - setLoading(false) - } - } - } - - getProducts() - - return () => { - cancelled = true - } - }, []) + const { products, loading, error } = useProducts() if (loading) { return
Загрузка продуктов...