I encountered an error while trying to populate a dropdownlist with the result from an async function. The error message reads: "Type '() => IDropdownOption[]' is not assignable to type 'IDropdownOption[]'." Despite my efforts, I have been unable to identify the root cause of this issue.
I am seeking assistance from anyone who can help me troubleshoot. Below is the code snippet:
Outline of the interface:
export interface countryChoices{
id: string;
text: string;
selected: boolean;
key: string;
}
The following function retrieves the values:
private async _getCountryForComboList()
{
let infos:IOrderedTermInfo[];
await this._services.getCountryListFromTermStore().then((response:any) => {
infos=response;
let CountryList:Array<countryChoices> = new Array<countryChoices>()
for(let i=0;i<infos.length;i++)
{
let CountryChoice:countryChoices={
id:i.toString(),
selected:false,
key:"CountryChoice",
text:infos[i].labels[0].name
};
CountryList.push(CountryChoice);
}
return CountryList;
}).catch((err) => {
console.error(err);
throw err;
});
}
Incorporating it into the React render():
<Dropdown className="w-100 p-3"
label="Select a Country"
options={this._getCountryForComboList}
/>
The aforementioned error occurs in relation to the "options" prop.
Your assistance is greatly appreciated.