I am fetching json using the Svelte onMount. I have an issue with getting the return json outside the onMount statement.
This is how i fetch my JSON using onMount:
let testData = [];
onMount(async () =>{
const resp = await fetch('http://localhost:3000/api/tableinfo.json');
testData = await resp.json();
console.log(testData); //Returns me array of objects
});
Console.log(testData) // return me []
How do I pass the array of objects and store in testData so that I can call testData with the array in another file?
Thank you.