'Promise<IDropdownOption[]> to <IDropdownOption[]>

I have this function where I get the value of fields from my spfx list:

async getFieldOptions(){
    const optionDrop: IDropdownOption[]= [];
    const variable: IEleccion = await sp.web.lists.getByTitle("Groups").fields.getByTitle("Sector").get()
    let items: IListItem[] = [];
     variable.Choices.forEach(vari=>{
        optionDrop.push({key: vari, text: vari})
     }) 
     return optionDrop
     
} 

Then I want to get those values to insert them in a html Dropdown, but I obtain an error because my function returns a promise and "options" require a 'IDropdownOption[] ' and I don't know how to solve it:

<Dropdown
      options={ListGroupService.getFieldOptions()}
/>


Solution 1:[1]

Use useState and useEffect.

const Component = () => {
    const [options, setOptions] = useState<IDropdownOption[]>();
    
    useEffect(() => {
      ListGroupService.getFieldOptions().then(setOptions);
    }, [])
    
    if(!options){
      return <>Loading...</>
    }
    
    <Dropdown options={options} />
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 darbaidze2020