I'm using Reactjs and want to return an object to another .jsx file coming from a fetch request. I'm a NOOB and for the last 4 days have been trying many permutations based on what I've read on stackoveroverflow and nothing has worked. (Yes, I know "obj" doesn't in the code below doesn't do anything. It's just my last round of trying something new.) Basically, I have a file called Getdata.jsx (the code below) and want it to return to another .jsx file an object containing values derived from a call to an api. The console.log works correctly (no surprise as it is inside a Promise). Here is my current iteration, which also fails:
var obj;
async function pullAPI() {
fetch("http://localhost:5000/api/customers", { method: "get" })
.then((res) => res.json())
.then((data) => (obj = data))
.then(() => console.log(obj));
}
async function myCall() {
const info = await pullAPI();
return info;
}
var Getdata = myCall();
export default Getdata;