You can also use the value
property of IonSelect
to set a value. Here’s an example:
function App() {
const INITIAL = "dog2";
const [value, setValue] = React.useState(INITIAL);
const options = ["dog1", "dog2", "dog3"];
return (
<IonItem>
<IonLabel>Select a Dog</IonLabel>
<IonSelect value={value} onIonChange={e => setValue(e.detail.value)}>
{options.map((option, i) => (
<IonSelectOption value={option} key={i}>
{option}
</IonSelectOption>
))}
</IonSelect>
</IonItem>
);
}
As long as INITIAL
is one of the options, it will be displayed as selected.