import React from "react"
import { Products } from '../Products'
class Main extends React.Component {
state = {
products: [],
}
componentDidMount() {
fetch('./products.json' )
.then((responce) => responce.json())
.then((data) => this.setState({products:data}))
}
render() {
const {products} = this.state;
return (
<main className="container content" >
<Products products={products} />
</main>
);
}
}
export {Main}
function Product (props) {
const {
prod_id: id,
prod_name : title,
prod_status: status,
prod_price: price,
prod_oldprice : oldPrice
} = props;
return <div className="product_item">
<img className="product_img" src="" alt="" />
<h3 className="product_title">{title}</h3>
<hr />
<div className="product_price">{price}</div>
<div className="product_old_price">{oldPrice}</div>
<div className="id">{id}</div>
<div className="status">{status}</div>
</div>
}
export {Product}
import {Product} from './Product';
function Products (props) {
const {products = []} = props;
return (
<div className="products">
{products.length ? (
products.map((product) => <Product key={product.prod_id} {...product} />)
) : (
<h4>Nothing found</h4>
)}
</div>
);
}
export {Products}
import React from "react";
import { Products } from "../Products";
class Main extends React.Component {
state = {
products: [],
};
componentDidMount() {
fetch("./products.json")
.then((responce) => responce.json())
.then((data) => this.setState({ products: Object.values(data) }));
}
render() {
const { products } = this.state;
return (
<main className="container content">
<Products products={products} />
</main>
);
}
}
export { Main };