I’m using the Select component for an app, but although an option is selected by default the initial UI still says “choose an option”.
See attached screenshots for an additional explanation (screenshot 1 with the default state, screenshot 2 is in the ‘clicked’ state without any selection).
What I’m looking for: Have ‘Emerging Threats’ already visible in the drop down when I’m loading the page as it’s selected by default.
It might be worth to look into the data types that are needed for defaultSelectedId, but here is how I could preselect a value:
1.) I run a useEffect that listens to my selection state (source in my example). It also runs when the page is rendered initially.
2.) If that source var is null (ie on the first render of the site), I set it to the desired preselected state, which preselects it. This way I can also query my result set right away.
I don’t need defaultSelectedId at all - my select field looks like this:
I don’t now for sure, but it seems like defaultSelectedId is tricky to use. I couldn’t find the correct type for hours. I tried different casts, putting my array selection into brackets, etc. etc.. Documentation should be improved on that end.