diff --git a/db.json b/db.json
new file mode 100644
index 0000000..8c31a69
--- /dev/null
+++ b/db.json
@@ -0,0 +1,25 @@
+{
+ "products": [
+ {
+ "id":1,
+ "name":"Sneakers Red & White 2025",
+ "brand":"NIKE",
+ "price":38.0,
+ "imageUrl":"./assets/images/sneakers-image.jpg"
+ },
+ {
+ "id":2,
+ "name":"Sneakers Red & White 2025",
+ "brand":"NIKE",
+ "price":40.0,
+ "imageUrl":"./assets/images/sneakers-image.jpg"
+ },
+ {
+ "id":3,
+ "name":"Sneakers Red & White 2025",
+ "brand":"NIKE",
+ "price":46.0,
+ "imageUrl":"./assets/images/sneakers-image.jpg"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/package.json b/package.json
index d79c61a..ad4f519 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
+ "server": "json-server --watch db.json --port 8000",
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
diff --git a/src/App.jsx b/src/App.jsx
index c144e38..aaf6c13 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -3,6 +3,67 @@ import SneakersImage from './assets/images/sneakers-image.jpg'
import { FaRegUser } from 'react-icons/fa'
import React from 'react'
+function EffectComponent() {
+ const [size, setSize] = React.useState(100);
+ const boxRef = React.useRef(null);
+
+ React.useEffect(() => {
+ const box = boxRef.current
+ if (box) {
+ const { width, height } = box.getBoundingClientRect()
+ console.log('[useEffect] Размеры (EffectComponent):', { width, height })
+ }
+ }, [size]);
+
+ return (
+
+
useEffect
+
+
+
+ )
+}
+
+function LayoutEffectComponent() {
+ const [size, setSize] = React.useState(100)
+ const boxRef = React.useRef(null)
+
+ React.useLayoutEffect(() => {
+ const box = boxRef.current
+ if (box) {
+ const { width, height } = box.getBoundingClientRect()
+ console.log('[useLayoutEffect] Размеры (LayoutEffectComponent):', {
+ width,
+ height,
+ })
+ }
+ }, [size])
+
+ return (
+
+
useLayoutEffect
+
+
+
+ )
+}
+
function Header() {
const handleChange = event => {
const newValue = event.target.value
@@ -13,7 +74,7 @@ function Header() {
Store
-
+
@@ -23,9 +84,23 @@ function Header() {
)
}
+function ToolTip() {
+ const ref = React.useRef(null);
+ const [height,setHeight] = React.useState(0);
+
+ React.useLayoutEffect(()=>{
+ if (ref.current) {
+ const rect = ref.current.getBoundingClientRect();
+ setHeight(rect.height);
+ }
+ },[])
+
+ return
Высота: {height}
+}
+
function Product() {
const [isLiked, setIsLiked] = React.useState(false)
-
+
const toggleLike = () => {
setIsLiked(!isLiked)
}
@@ -37,6 +112,7 @@ function Product() {
return (

+
Sneakers Red & White 2025
@@ -68,7 +144,19 @@ function Product() {
}
function App() {
- return (
+ const [products,setProducts] = React.useState([]);
+
+ const getProducts = async () => {
+ const responce = await fetch('http://localhost:8000/products');
+ const data = await responce.json();
+ setProducts(data);
+ }
+ React.useEffect(() => {
+ getProducts();
+ },[]);
+
+
+ return (
<>
@@ -86,6 +174,8 @@ function App() {
+
+
>
)
}