My code is written with React and I am trying to conditionally swap what gets assigned to value in each element. swap is being passed in as a prop and I thought it would work to act as the trigger but I get no change when I use swap=true vs swap=null.
function DataList({label, onSelect, options, swap}) {
return (
<DataListContainer>
<CustomInput placeholder={label} list="items" name="item" id="item" required onChange={onSelect}></CustomInput>
<datalist id='items' >
{options? options.map(option => <option key={option.number} value={swap ? option.title : option.number}>{swap ? option.number : option.title}</option>) : null}
</datalist>
</DataListContainer>
);
}
<DataList
label='Select Chapter Number'
onSelect={changeChapterNumber}
options={chaptersFromSelectedComic}
/>
<DataList
label='Select Chapter Title'
onSelect={changeChapter}
options={chaptersFromSelectedComic}
swap={true}
/>