I have a homepage where 3 cards are shown. When a specific card is clicked then the image will show. Now I can change the route but I am not able to show image and heading. Because all it is saying is destructuring undefined. The console log is showing the JSON data though.
Here is parent component:
import React, { useState } from "react";
import { Link } from "react-router-dom";
import DetailsOfDestination from "../DetailsOfDestination/DetailsOfDestination";
import FakeData from "../Fakedata/FakeData";
const PlaceDetail = (props) => {
const [info, setInfo] = useState(FakeData);
const { heading, img, text } = props.place;
return (
<div>
{info.map((singleInfo) => (
<DetailsOfDestination singleInfo={singleInfo}></DetailsOfDestination>
))}
<Link to={`/DetailsOfDestination`}>
<img src={img} alt="" />
</Link>
</div>
);
};
export default PlaceDetail;
Here is child component:
import React from "react";
const DetailsOfDestination = (props) => {
console.log(props.singleInfo);
const { heading, img } = props.singleInfo;
//console.log(heading);
return (
<div>
<h1>{heading}</h1>
</div>
);
};
export default DetailsOfDestination;
My Fake Data:
const data = [
{
img: "https://i.ibb.co/pxgYz0b/Group-1333.png",
heading: "Cox Bazar",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s,",
},
{
img: "https://i.ibb.co/3dLyGVd/Group-1335.png",
heading: "Sreemangal",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s,",
},
{
img: "https://i.ibb.co/qkHmMFD/Group-1337.png",
heading: "Sundarban",
text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s,",
},
];
export default data;
I'm getting an error. It says:
"Cannot destructure property
heading
ofprops.singleInfo
as it is undefined"