Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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()}
/>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use useState and useEffect.

const Component = () => {
    const [options, setOptions] = useState<IDropdownOption[]>();
    
    useEffect(() => {
      ListGroupService.getFieldOptions().then(setOptions);
    }, [])
    
    if(!options){
      return <>Loading...</>
    }
    
    <Dropdown options={options} />
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!