I am working on someone else's code and trying to figure out how to render a list alphabetically in React. I didn't write any of this and have very little knowledge of React, so please bear with me.
The ul looks like this:
<ul className="prod-group__filter__options" ref={(options) => this.options = options}> { filter.dropdown.map((option, index) => ( this.renderOption(filter, option, index) )) } </ul> and the renderOption function, which obviously renders the list items looks like this:
renderOption(filter, option, index) { return ( <li className="prod-group__filter__option" key={index}> <label className="prod-group__filter__option__label"> <input name={filter.name} type="checkbox" defaultValue={option.slug} checked={option.checked} onChange={this.optionChangeHandler} /> {option.label} </label> </li> ); } The value I am trying to alphabetize is option.slug which is coming from a json list. Can anyone help me get a bit closer to rendering this list alphabetically?