I have multiple elements that are coming dynamically and the markup is like this:
<li>
<div>
<input type="radio" value="abc" name="abc">
<span>ABC</span>
</div>
</li>
<li>
<div>
<input type="radio" value="bcd" name="bcd">
<span>BCD</span>
</div>
</li>
What I need is to sort these elements in react? What would be the best approach here? to sort value or name or span content and how to do so?
Currently I'm mapping them:
const RadioButtonComponent = ({question, setAnswer, answer, lang}) => {
const radioSingleElement = question.options.map((opt) => {
return <li onClick={() => setAnswer(option.value)}>
<Radio className="r-buttons" value={opt.value}} /><span>{question.useKeysForLabels ? lang[opt.label] : opt.label}</span>
</li>
});
return (
<RadioGroup name={question.name} selectedValue={answer} onChange={(value) => {setAnswer(value);}>
<ul>
{radioSingleElement}
</ul>
</RadioGroup>
)
}
<input>value, though that would be a personal opinion, and asking for those would be off-topic for StackOverflow.JavaScript. See this question: stackoverflow.com/questions/46923526/….