I'm trying to get the grand child value from local json file. It will work perfectly all other pages. But I couldn't get the value while using useEffect. I can get child object value. But I'm not able to get the grand child value.
import React, { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom';
const ProductDetails = (props) => {
const [Product, SetProduct] = useState({});
const { ProductId } = useParams();
const GetProduct = props.ProductData.products;
useEffect(() => {
const GetItem = (item) => {
item.forEach(element => {
if (element.id === ProductId) {
SetProduct(element)
}
});
}
GetItem(GetProduct)
}, [GetProduct, ProductId])
console.log(Product.img.thumbnail)
This is my JSON structure
"products": [
{
"id": "",
"code": "",
"name": "",
"img": {
"homeSlider": "",
"thumbnail": "",
"cover": [
{
"front": "",
"back": "",
"side": ""
}
]
}
},
{
"id": "",
"code": "",
"name": "",
"img": {
"homeSlider": "",
"thumbnail": "",
"cover": [
{
"front": "",
"back": "",
"side": ""
}
]
}
}
]
Please help me for this situation. Thanks.
