I'm trying to abstract away a data load function that uses promises, but now I'm unsure how to call that function from another module... :(
dataservice module
export default class DataService {
loadStudents() {
return window.fetch("data.json")
.then(res => res.json())
.then(res => {
// I want to return the result not a promise?
return res
})
}
}
main app module
import DataService from "../classes/dataservice"
const ds = new DataService()
ds.loadStudents().then(res => {
// here I just want the data, not a promise...
console.log(res)
})