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?