I'm using a table/grid js library that allows me to give it a function that will be called upon user right-click to display some data in a menu. The function's return type is Array<String>
. However, I would like to perform an async action (load data from a network request) in my function and use its result in my function return value. How can I do this via callbacks or otherwise?
function getMenuItems(): Array<string>{
const resp: Promise = asyncLoadData()
//How can I use this async construct in my sync function???
const items = ... //e.g. map resp into my return value.
return items
}
To be clear, getMenuItems()
is a parameter to a 3rd party library and i I cannot change the return value of it to accept a promise or change the method to be async