Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 29, 2022 11:35 am GMT

React, Vue and Svelte : Comparing Select binding

Select Binding in...

You will notice that without any extra code, React will select the next value because the first one is disabled. Vue and Svelte leave the select empty.

Check it out

React

Live Example

const [selected, setSelected] = useState<string>('Choose one option');<section>    <h2>Select</h2>    <select onChange={(e) => setSelected(e.target.value)}>        <option value="" disabled>        Please select one        </option>        <option>Frontend Developer</option>        <option>Backend Developer</option>        <option>Fullstack Developer</option>    </select>    <p>Selected: {selected}</p></section>

Vue

Live Example

const selected = ref('Choose one option');<section>    <h2>Select</h2>    <select v-model="selected">      <option value="" disabled>Please select one</option>      <option>Frontend Developer</option>      <option>Backend Developer</option>      <option>Fullstack Developer</option>    </select>    <p>Selected: {{ selected }}</p></section>

Svelte

Live Example

let selected: string = 'Choose one option';<section>    <h2>Select</h2>    <select bind:value={selected}>      <option disabled value="">Please select one</option>      <option>Frontend Developer</option>      <option>Backend Developer</option>      <option>Fullstack Developer</option>    </select>    <p>Selected: {selected}</p></section>

Original Link: https://dev.to/ccreusat/react-vue-and-svelte-comparing-select-binding-4cha

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To