Skip to content

Instantly share code, notes, and snippets.

@asiniy
Last active April 7, 2020 16:23
Show Gist options
  • Save asiniy/81a4d383003d4ee6380d4cc4441a359d to your computer and use it in GitHub Desktop.
Save asiniy/81a4d383003d4ee6380d4cc4441a359d to your computer and use it in GitHub Desktop.
const currentLanguage = 'ru' // store this in global state (redux, window, localStorage, flux et.c.)
const countries = [
{
ru: 'Россия',
en: 'Russia',
}, {
ru: 'США',
en: 'USA'
},
// et.c.
]
onSelect = (selectedCountry) => {
this.setState({ selectedCountry })
}
<select onSelect={onSelect}>
{countries.map((country) => (
<option selected={country === this.state.selectedCountry}> // maybe, you have to compare values not objects due to shallow comparison
{country}
</option>
)}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment