So, I have this function called !HandleDetail that gets the item once clicked and loads a detail screen. When this reloads, it shows only one object no matter what object I clicked on. So if I clicked on a iPhone, and I reload the browser, it reloads with the only item (a T-shirt) object showing. I am sure this has something to do with state as I fixed other bugs like this using state. I am thinking I have to map over the created array to gather the information and set the state of it. Here is a video showing what I mean: https://tyriquedaniel14-gmail.tinytake.com/tt/MzYwMDcwN18xMDg4NTEzMQ. To make things clear, I am trying to have the detail state show the corresponding item with the same id.
state = {
products: [],
clothing: [],
gadget: [],
smoke:[],
detailProduct: detailProduct,
cart: [],
modalOpen: false,
modalProduct: detailProduct,
cartSubTotal: 0,
cartTax: 0,
cartTotal: 0
};
getItem = id => {
const product = this.state.products.find(item => item.id === id);
return product;
};
handleDetail = id => {
const product = this.getItem(id);
this.setState(() => {
return { detailProduct: product };
});
};
export const detailProduct = {
id: 1,
title: "COMME DES GARCONS TEE",
img: "img/product-1.png",
img2: "img/product-1-1.png",
img3: "img/product-1-2.png",
img4: "img/product-1-3.png",
luxury: "All Luxuryitems are inspected to verify authenticity",
price: 200,
info: " COMME DES GARCONS PLAY BASIC LOGO TEE",
inCart: false,
count: 0,
total: 0,
size1: "Small",
size2: "Medium",
size3: "Large",
size4: "Extra Large",
fabric: "100% Cotton",
category: "Mens Fashion"
};
This is My router link
<Link to="/details">
I am trying to turn this into an array of all products. I have tried adding the map method and setting detailProduct to product.