Created
January 16, 2022 15:44
-
-
Save tetrashine/77b965a8ccdb094f90d81d5597c93004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const subCategoryHoc = (Component) => { | |
return (props) => { | |
const { onCountryChange, onCityChange } = props; | |
const [selectedOption, setSelectedOption] = useState("canada"); | |
const cities = { | |
"canada": ["Toronto", "Quebec City", "Vancouver"], | |
"china": ["Shanghai", "Beijing", "Guangzhou"], | |
"japan": ["Sapporo", "Tokyo", "Yokohama"], | |
"us": ["New York", "Los Angeles", "Chicago"], | |
}; | |
const onChange = e => { | |
const country = e.target.value; | |
setSelectedOption(country); | |
onCountryChange(country); | |
}; | |
return ( | |
<select id="cars" name="country" onChange={onChange} value={selectedOption}> | |
<option value="canada">Canada</option> | |
<option value="china">China</option> | |
<option value="japan">Japan</option> | |
<option value="us">U.S</option> | |
</select> | |
<Component cities={cities[selectedOption]} onChange={onCityChange} /> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment