Topic: MDBSelect get the sSelectedData value
cariforef free asked 2 years ago
Hy, I want to get to selectedData value, but I get an error on the e element because it is defined as a SelectedData | SelectedData[] type... How can I get the e.value of the selected item. It is a single select, not multiple, so the e should be a SelectedData and not an array.
<MDBSelect
label="Trier par"
onValueChange={(e) => {
console.log(e);
setSort(e.value);
search.set("sort", e.value);
setSearch(search, {
replace: true,
});
}}
data={[
{
text: "Intitulé ASC",
value: "for_intitule_txt_fr asc",
},
{
text: "Date de début",
value: "date_debut_session_dt asc",
defaultSelected: true,
},
{
text: "Ville DESC",
value: "ville_lieu_formation_s desc",
},
]}
name="sort"
/>
The console log send me the correct object SeletedData :
{ "text": "Ville DESC", "value": "ville_lieu_formation_s desc" }
Thanks, Didier
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Opened
- ForumUser: Free
- Premium support: No
- Technology: MDB React
- MDB Version: MDB5 4.0.0
- Device: MAC
- Browser: Chrome
- OS: MAC OS 10.15
- Provided sample code: No
- Provided link: No
Krzysztof Wilk staff commented 2 years ago
Hi!
Can you show me the error message you got or create a simple app on GitHub to show the issue? Everything looks fine in your code. I'm afraid I can't reproduce it on my side right now because I don't have an access to your states or methods you are using in
onValueChange
:)