Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Svelte 5 form data not reactive in submit handler

$
0
0

I am trying to implement a form submit action in Svelte 5 but I am having some issues with reactivity it seems.

<script>    const formData = $state({        name: 'abc',    })    const saveData = (e) => {        e.preventDefault()        console.log(formData)    }</script><form onsubmit={saveData}><input type="text" bind:value={formData.name}/><button type="submit">        Create</button></form><pre>{formData.name}</pre>

As expected, the {formData.name} displays the correct value, but the console.log(formData) always outputs abc no matter what I enter in the form. How would I retrieve the most recent value in the submit handler?


Viewing all articles
Browse latest Browse all 1541

Trending Articles