Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind a store variable in Svelte?

Tags:

svelte

I am trying to bind a variable from my store to a component, but get the error:

[!] (plugin svelte) ValidationError: Cannot bind to a variable which is not writable

Here is my sample code:

<Textfield bind:value={startDate} label="Start Date" type="datetime-local" />
like image 973
Jeremy Cochoy Avatar asked Nov 25 '25 09:11

Jeremy Cochoy


1 Answers

To use a store variable, one can rely on the "update" callback, or use the specific syntax

<Textfield bind:value={$startDate} label="Start Date" type="datetime-local" />

More information on the Svelte tutorial: https://svelte.dev/tutorial/store-bindings

like image 70
Jeremy Cochoy Avatar answered Nov 28 '25 17:11

Jeremy Cochoy