Data is reactive and can be used as state.
Reassigning a variable will invalidate the component and trigger an update. After an update is triggered, Svelte will update the DOM to reflect the new state.
Svelte uses let
variables to hold local component state.
In this example, we'll create an AddTodo
component to add new todos.
Data is reactive and can be used as state.
Reassigning a variable will invalidate the component and trigger an update. After an update is triggered, Svelte will update the DOM to reflect the new state.
To update an object or an array, it must be reassigned.
A more succinct way to bind state to an element or a component is with Svelte's bind:
attribute prefix.
Reassigning an array will trigger a change.
Mutating an array and reassigning it will trigger a change.
Mutating an array will not trigger a change.
Reassigning an object will trigger a change.
Mutating an object and reassigning it will trigger a change.
Mutating an object will not trigger a change.
Further reading on this topic.