Skip to content
Snippets Groups Projects
Commit a1342843 authored by PatrickMurphy99's avatar PatrickMurphy99
Browse files

printed out the selected country

oooof
parent 361678c0
No related branches found
No related tags found
No related merge requests found
import React from 'react';
import React, {useEffect, useState} from 'react'
import './App.css';
import DropDown from './components/DropDown';
function App() {
const [selectedCountry, changeCountry] = useState<string>("")
const countryFunction = (event:React.ChangeEvent<HTMLSelectElement>):void => {
changeCountry(event.target.value);
}
return (
<div className="App">
<DropDown geoOption='countries' name='country_name' code='country_code'/>
<DropDown geoOption='countries' name='country_name' code='country_code' changeFunction={countryFunction}/>
<p> This is our selected country {selectedCountry}</p>
</div>
);
}
export default App;
......@@ -4,6 +4,7 @@ interface DropDownProp {
geoOption: string;
name: string;
code: string;
changeFunction(event: React.ChangeEvent<HTMLSelectElement>):void;
}
......@@ -18,7 +19,8 @@ export default function DropDown(props: DropDownProp) {
}, [props.geoOption]);
console.log(options);
return (
<select> {options.map((optionItem:any) =><option key={optionItem[props.code]}
<select onChange={props.changeFunction}
> {options.map((optionItem:any) =><option key={optionItem[props.code]}
value={optionItem[props.name]}>{optionItem[props.name] + " (" + optionItem[props.code] + ")"}</option>)} </select>
);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment