I have a static json file appyling this format:
[
{/*OBJECT1*/}, {/*OBJECT2*/} /* SO ON ... */
]
I wanted to fetch data to my React Component from this JSON file
I fetch the data in my React component by using following code
useEffect(() => {
async function getEssayData() {
const res = await fetch('/essayData.json');
const data = await res.json();
return data;
}
const fetchData = getEssayData();
console.log('Result Data ' + fetchData);
console.log(fetchData);
console.log('Data ' + data[0]);
}, []);
i've tried lots of things, this is only one of them; however i couldn't reach my objects inside of JSON file.
(Fetching is happening correctly but i couldn't reach data objects ...)
console image , i really appreciate if you can help me with that.
console.logoperations to inside the function. All the effect should be doing is calling the function, all of the logic in this case should be inside thegetEssayDatafunction.getEssayData(). It returns aPromise.