I have an array like this in React data file and I'm using the .map() method to load JSON data in component ProjectItem.js.
What is the most efficient way to print nested JSON object? I now want to print the title in projects array so I can debug it, show it on browser. I can't see <div className="title"></div> in inspector, what is the right function?
Data.json
{
"projects": [
{
"title": "Projecttitle1",
"category": "frontend development",
"description": "",
"desktop": [],
"mobile": []
}
]
}
ProjectItem.js
import React from 'react';
import './ProjectItem.scss';
import useWindowWidth from '../../Hooks/useWindowWidth.js';
import { projects } from '../../data'
import desktopImage from '../../Assets/Images/Projects/Desktop/123.jpg';
import mobileImage from '../../Assets/Images/Projects/Mobile/123_square.jpg'
const ProjectItem = ({ viewProject }) => {
const imageUrl = useWindowWidth() >= 650 ? desktopImage : mobileImage;
const { windowWidth } = useWindowWidth();
return(
<div className="projectItem" style={{ backgroundImage: `url(${ imageUrl })`}}>
{windowWidth >= 650 &&(
<>
<div className="title">
{projects.map((data, key)=>{
console.log(key);
return(
<div key={key}>
{data.title}
</div>
);
})}
</div>
<div className="viewProject">{viewProject}</div>
</>
)}
</div>
);
};
export default ProjectItem
Console:
empty
projects? Can put log before map and check once?{console.log(json.projects.title)}and ` {console.log(projects[0].title)}` to check once, no log data appears :({console.log("title" + projects[0].title)}and log data Projecttitle1 appears on console, please if someone can put me on right track to print using map function