Nobody seems to be able to help me with this and I am really unsure.
I am using React-Select drop down and doing an async call to get data from an API.
Here is my type :
type Person = {
value: string;
label: string;
};
Here is my promise for the data api :
const fetchDropDown = async () : Promise<Array<Person>> => {
try {
const stuff = await dynamicsWebApi.retrieveAll("accounts",["name"]);
const records = stuff.value;
const options = records?.map<Person>(d => ({
"value": d.name,
"label": d.name
}));
console.log(options)
return options as Person[]
} catch (error) {
if (error) {
console.log(error)
throw(error)
}
}
}
And here is my react component :
<div>
<AsyncSelect
cacheOptions
defaultOptions
loadOptions={fetchDropDown}
/>
At the top of the promise on this line :
const fetchDropDown = async () : Promise<Array<Person>> => {
I am getting the error :
Function lacks ending return statement and return type does not include 'undefined'
I know I am nearly there but I just cannot seem to get this final bit working so in the drop down I can see my rows from the API.
I need someone who truly knows the stuff to help me along with this.
So to get the component to drop down with the rows, I need it to be in a value/label pair and that's why I have gone with the .map command.
Can anyone help ? Thanks