Here, I am trying to load a local JSON file using the async function. I am trying to log the data in the console, any solutions?
import { useEffect } from "react";
import "./styles.css";
export default function App() {
useEffect(() => {
fetchItems();
});
const fetchItems = async () => {
const res = await fetch("./users.json");
const data = await res.json();
console.log(data);
};
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
</div>
);
}
Here is my JSON file named users.json.
[
{
"id": 1,
"first_name": "random",
"last_name": "random"
}, {
"id": 2,
"first_name": "random",
"last_name": "random"
}
]