I need to display a dropdownlist element with some optgroup labels in my react components.
So I created this method :
onRenderCategories: any = () => {
var scope = "";
var rendu = "";
for (var scopes in this.props.categories) {
var ensemble: Array<CategoryTemplateInfos> = this.props.categories[scopes];
if (ensemble.length == 0) continue;
scope = ensemble[0].scope;
rendu += "<optgroup label=" + scope + ">";
for (var j = 0; j < ensemble.length; j++) {
var categorie: string = ensemble[j].label;
var id_categorie: string = ensemble[j].id;
rendu += "<option value=" + id_categorie+">" + categorie+"</option>";
}
rendu += "</optgroup>";
}
return rendu;
}
the output of this method is as excepted ie the html content to put here
<select >
<option value="">--Please select a category--</option>
{this.onRenderCategories()} //here
</select>
It didn't work!
So how can I fix this issue to convert a string to HTML elements ?
Thanks,
onRenderCategoriesmethod?{this.onRenderCategories}