DEV Community

Cover image for React, Vue and Svelte: Comparing Multi Select Binding
Clément Creusat
Clément Creusat

Posted on

7 3

React, Vue and Svelte: Comparing Multi Select Binding

Multi Select Binding in...

Woo ! This is it. The end of this series. We've seen a lot of concepts to compare between these frameworks. Hope it helped people!

Check it out 🚀

React

Live Example

const [multiSelected, setMultiSelected] = useState<string[]>([
    'Frontend Developer',
]);
const handleMultiSelected = (options: any) => {
let selectedOptions = [...options]
    .map((option) => option.value)
    .reduce((prev, current) => [prev, ', ', current]);

setMultiSelected(selectedOptions);
};

<section>
    <h2>Multi Select</h2>
    <select multiple style={{ width: '100px' }} onChange={(e)=> handleMultiSelected(e.target.selectedOptions)}
        >
        <option>Frontend Developer</option>
        <option>Backend Developer</option>
        <option>Fullstack Developer</option>
    </select>
    <p>Selected: {multiSelected}</p>
</section>

Enter fullscreen mode Exit fullscreen mode

Vue

Live Example

const multiSelected = ref(['Frontend']);

<section>
    <h2>Multi Select</h2>
    <select v-model="multiSelected" multiple style="width: 100px">
        <option>Frontend Developer</option>
        <option>Backend Developer</option>
        <option>Fullstack Developer</option>
    </select>
    <p>Selected: {{ multiSelected }}</p>
</section>

Enter fullscreen mode Exit fullscreen mode

Svelte

Live Example

let multiSelected: string[] = ['Frontend Developer'];

<section>
    <h2>Multi Select</h2>
    <select bind:value={multiSelected} multiple style="width: 100px">
        <option>Frontend Developer</option>
        <option>Backend Developer</option>
        <option>Fullstack Developer</option>
    </select>
    <p>Selected: {multiSelected}</p>
</section>

Enter fullscreen mode Exit fullscreen mode

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →