I have the following below 2 functions attempting to get data out of a mongo database from an express server endpoint I have set up. This code is in my React front-end app.
export function getContacts() {
let data = fetch('/api/contacts').then((data) => {
return data.json();
}).catch(err => console.log(err));
return data;
}
and the following that calls it
const initialState = getContacts()
.then((body) => {
console.log('body: ');
console.log(body);
return body;
}).catch(err => console.log(err));
when I log body
it is a promise. I was expecting a json array of documents from the db. My getContacts() is supposed to return a promise and then my callback in initialState gets the data from it.