Создали асинхронную функцию getProducts для получения продуктов с сервера

This commit is contained in:
isHardCoded
2025-06-25 15:38:08 +03:00
parent 2812645834
commit ca519f47b1
+14
View File
@@ -68,6 +68,20 @@ function Product() {
} }
function App() { function App() {
const [products, setProducts] = React.useState([])
const getProducts = async () => {
const response = await fetch('http://localhost:8000/products')
const data = await response.json()
setProducts(data)
}
React.useEffect(() => {
getProducts()
}, [])
console.log(products)
return ( return (
<> <>
<div className={styles.container}> <div className={styles.container}>