I have this function:
const buildDataSource = (): Promise<Data> => {
const data = fetch('https://jsonplaceholder.typicode.com/posts')
.then((response) => response.json())
.then((items) => items.map((item: RawDataItem, idx: number) => ({
key: idx,
randStr: item.title.substring(1, 24),
})));
return data;
};
And call it with this: const data = buildDataSource();
but data
is a resolved promise that includes the data, not the data itself. Where am I going wrong here?