I'm trying to add flags to the language selection menu using the Semantic-Ui Flag element. I'm using React 16.13.1.
When placing a flag segment in the option, the code simply displays [object] in the selection box. I tried to put the flag in a separate div next to it, but I can't make the flag dependent on the currently selected language. How do I hook it? Is there any way to display the flag inside the dropdown menu?
import React from "react";
import { Flag, Segment } from 'semantic-ui-react'
const languages = ['ae', 'ar', 'at', 'au', 'be', 'bg', 'br', 'ca', 'ch', 'cn', 'co', 'cu',
'cz', 'de', 'eg', 'fr', 'gb', 'gr', 'hk', 'hu', 'id', 'ie', 'il', 'it', 'jp', 'kr',
'lt', 'lv', 'ma', 'mx', 'my', 'ng', 'nl', 'no', 'nz', 'ph', 'pl', 'pt', 'ro', 'rs',
'ru', 'sa', 'se', 'sg', 'si', 'sk', 'th', 'tr', 'tw', 'ua', 'us', 've', 'za']
class Languages extends React.Component {
constructor(props) {
super(props);
this.state = {
value: "pl",
}
}
onValueChange = (e) => {
const value = e.target.value;
this.setState({ value});
this.props.onLanguageChange(value);
};
render () {
const { value } = this.state;
return(
<select value={value} onChange={this.onValueChange}>
{languages.map((lang) => (
<option key={lang} value={lang}>{lang}<Segment> <Flag name={lang}/> </Segment> </option>))}
</select>
)
}
}
export default Languages;