Skip to content
Snippets Groups Projects
DropDown.tsx 917 B
Newer Older
import React, {useEffect, useState} from 'react'

interface DropDownProp {
    geoOption: string;
PatrickMurphy99's avatar
PatrickMurphy99 committed
    name: string;
    code: string;
    changeFunction(event: React.ChangeEvent<HTMLSelectElement>):void;
export default function DropDown(props: DropDownProp) {
PatrickMurphy99's avatar
PatrickMurphy99 committed
    const [options, setOptions] = useState<Object[]>([]);
PatrickMurphy99's avatar
PatrickMurphy99 committed
        const updateGeoOptions =  async () => {
            const fetchedOptions:Object[] = await (await fetch("http://127.0.0.1:8000/" + props.geoOption + "/")).json();
            setOptions(fetchedOptions)
PatrickMurphy99's avatar
PatrickMurphy99 committed
        updateGeoOptions();
PatrickMurphy99's avatar
PatrickMurphy99 committed
    console.log(options);
        <select onChange={props.changeFunction}
        > {options.map((optionItem:any) =><option key={optionItem[props.code]}
PatrickMurphy99's avatar
PatrickMurphy99 committed
         value={optionItem[props.name]}>{optionItem[props.name] + " (" + optionItem[props.code] + ")"}</option>)} </select>