I have a module that invokes a service
let getData = () => fetch("https://jsonplaceholder.typicode.com/posts")
.then(response => response.json())
.then(json => (getData = json));
export {getData };
I try to log to console the result (and put it on an HTML page) like this
import { getData } from "./api";
const app = document.querySelector("#target");
let data = getData()
.then(res => res.map(r => r.title).join("\n"))
.then(res => (data = res));
console.log(data);
app.innerHTML = data;
However, I get an unresolved promise like this [object Promise]
I've tried a few variations which also don't work
// none of these work don't work
// .then(async res => data = await res);
// .then(res => (data = Promise.resolve(res)));
Any suggestions as to what I am doing wrong?