Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230979

[Solved] Ion Select Selected Option

$
0
0

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.


Viewing all articles
Browse latest Browse all 230979

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>