Even though I have typed the code shown in the topic, I am not able to get the same output.
import ProductItem from './ProductItem';
import './Products.css';
function Products(props)
{
return <div className='products'>
<ProductItem
name = {props.product[0].name}
type = {props.product[0].type}
price = {props.product[0].price}
/>
<ProductItem
name = {props.product[1].name}
type = {props.product[1].type}
price = {props.product[1].price}
/>
<ProductItem
name = {props.product[2].name}
type = {props.product[2].type}
price = {props.product[2].price}
/>
<ProductItem
name = {props.product[3].name}
type = {props.product[3].type}
price = {props.product[3].price}
/>
</div>
}
export default Products;
This is App.js code
import Products from './components/ProductItem';
function App() {
const product = [
{name: 'Beginner to Advanced: React', type: 'Book', price: '2000'},
{name: 'Iphone 14', type: 'Mobile Phone', price: '80000'},
{name: 'Rework', type: 'Book', price:'900'},
{name: 'MacBook', type: 'Laptop', price: '150000'}
];
return (
<div>
<h1>
App Component
</h1>
<Products product = {product} />
</div>
);
}
export default App;
This is ProductItem.js code
import './ProductItem.css';
function ProductItem(props)
{
return(
<div className="product-item">
<div>
{props.name}
</div>
<div className = "product-item__type">
<p>
{props.type}
</p>
</div>
<div product-item__price>
{props.price}
</div>
</div>
);
}
export default ProductItem;
My output looks like this: