[Svelet Tutorial] 2. Reactivity
2. Reactivity
At the heart of Svelte is a powerful system of reactivity for keeping the DOM in sync with your application state.
a. Assignments
1 | <script> |
b. Declarations
Svelte automatically updates the DOM when your component’s state changes. Often, some parts of a component’s state need to be computed from other parts (such as a fullname derived from a firstname and a lastname), and recomputed whenever they change.
For these, we have reactive declarations. They look like this:
1 | <script> |
Of course, you could just write {count * 2}
in the markup instead — you don’t have to use reactive values. Reactive values become particularly valuable when you need to reference them multiple times, or you have values that depend on other reactive values.
References
[1] Reactivity / Assignments • Svelte Tutorial - https://svelte.dev/tutorial/reactive-assignments
[2] Svelte • Cybernetically enhanced web apps - https://svelte.dev/