Describe fetch-on-mount: set loading, then data—implement with async IIFE.
Ready — edit the code above and click Run.
async function loadData() {
return { id: 1, name: "Demo" };
}
(async () => {
let loading = true;
let data = null;
data = await loadData();
loading = false;
console.log({ loading, data });
})();
Try solving on your own first, then reveal the official answer.
Mount effect with cleanup is a top React interview topic—always mention abort/cancel for fetch.