I use react-select and want to use defaultValue but its not working.
here is my code:
<code> <Select className="select-type stp" defaultValue={brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)]} options={brandModel.map((el => ({
value: el,
label: el
})))} />
</code>
<code> <Select className="select-type stp" defaultValue={brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)]} options={brandModel.map((el => ({
value: el,
label: el
})))} />
</code>
<Select className="select-type stp" defaultValue={brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)]} options={brandModel.map((el => ({
value: el,
label: el
})))} />
if I console.log this
<code>brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)
</code>
<code>brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)
</code>
brandModel.map((el => ({
value: el,
label: el
})))[brandModel.findIndex(el => el === car?.model)
I get this:
<code>{label: '116', value: '116'}
</code>
<code>{label: '116', value: '116'}
</code>
{label: '116', value: '116'}
so the result are correct but why its not showing it
New contributor
cenk kandemir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.