Сделали дочерние компоненты и свойства
This commit is contained in:
@@ -2,14 +2,14 @@
|
|||||||
"products": [
|
"products": [
|
||||||
{
|
{
|
||||||
"id":1,
|
"id":1,
|
||||||
"name":"Sneakers Red & White 2025",
|
"name":"Кросовки Red & White 2025",
|
||||||
"brand":"NIKE",
|
"brand":"NIKE",
|
||||||
"price":38.0,
|
"price":38.0,
|
||||||
"imageUrl":"./assets/images/sneakers-image.jpg"
|
"imageUrl":"./assets/images/sneakers-image.jpg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":2,
|
"id":2,
|
||||||
"name":"Sneakers Red & White 2025",
|
"name":"Кросовки белые 2024",
|
||||||
"brand":"NIKE",
|
"brand":"NIKE",
|
||||||
"price":40.0,
|
"price":40.0,
|
||||||
"imageUrl":"./assets/images/sneakers-image.jpg"
|
"imageUrl":"./assets/images/sneakers-image.jpg"
|
||||||
|
|||||||
+34
-15
@@ -98,7 +98,7 @@ function ToolTip() {
|
|||||||
return <div ref={ref} style={{height: '40px'}}>Высота: {height}</div>
|
return <div ref={ref} style={{height: '40px'}}>Высота: {height}</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
function Product() {
|
function Product({ name, brand, price, url }) {
|
||||||
const [isLiked, setIsLiked] = React.useState(false)
|
const [isLiked, setIsLiked] = React.useState(false)
|
||||||
|
|
||||||
const toggleLike = () => {
|
const toggleLike = () => {
|
||||||
@@ -115,7 +115,7 @@ function Product() {
|
|||||||
<ToolTip />
|
<ToolTip />
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<div className={styles.title}>
|
<div className={styles.title}>
|
||||||
<h4>Sneakers Red & White 2025</h4>
|
<h4>{name}</h4>
|
||||||
<div className={styles.actions}>
|
<div className={styles.actions}>
|
||||||
<button
|
<button
|
||||||
className={styles.likeButton}
|
className={styles.likeButton}
|
||||||
@@ -136,13 +136,28 @@ function Product() {
|
|||||||
<button onClick={handleAddClick}>+</button>
|
<button onClick={handleAddClick}>+</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p className={styles.description}>NIKE</p>
|
<p className={styles.description}>{brand}</p>
|
||||||
<p className={styles.price}>$38.00</p>
|
<p className={styles.price}>${price}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MyComponent({ children }) {
|
||||||
|
return <div className="wrapper">{children}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function RowList({ children }) {
|
||||||
|
return (
|
||||||
|
<div className="rowList">
|
||||||
|
{children.map(child => (
|
||||||
|
<div className="row">{child}</div>
|
||||||
|
))}
|
||||||
|
<p>{React.Children.count(children)}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [products,setProducts] = React.useState([]);
|
const [products,setProducts] = React.useState([]);
|
||||||
|
|
||||||
@@ -154,8 +169,7 @@ function App() {
|
|||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
getProducts();
|
getProducts();
|
||||||
},[]);
|
},[]);
|
||||||
|
console.log({...products});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
@@ -163,19 +177,24 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<ul className={styles.list}>
|
<ul className={styles.list}>
|
||||||
|
{products.map(product => (
|
||||||
<li>
|
<li>
|
||||||
<Product />
|
<Product {...product} />
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Product />
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Product />
|
|
||||||
</li>
|
</li>
|
||||||
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
<MyComponent>
|
||||||
|
<h4>Заголовок</h4>
|
||||||
|
<p>Привет!</p>
|
||||||
|
</MyComponent>
|
||||||
|
<ol>
|
||||||
|
<RowList>
|
||||||
|
<li>первый</li>
|
||||||
|
<li>второй</li>
|
||||||
|
<li>третий</li>
|
||||||
|
</RowList>
|
||||||
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
<EffectComponent />
|
|
||||||
<LayoutEffectComponent />
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user