You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/docs/03-template-syntax/01-basic-markup.md
+19
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,25 @@ Curly braces can be included in a Svelte template by using their [HTML entity](h
158
158
159
159
If you're using a regular expression (`RegExp`) [literal notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#literal_notation_and_constructor), you'll need to wrap it in parentheses.
160
160
161
+
> [!NOTE] Svelte statically analyzes your code to determine what is actually reactive. As a result, if a text or attribute expression does not contain:
162
+
> - An object property
163
+
> - A function call
164
+
> - A reference to a reactive variable
165
+
>
166
+
> Then Svelte will treat it as a static expression that does not require updates. This means that this sort of statement would be treated as static, and would never update:
167
+
> ```svelte
168
+
> <script>
169
+
> let count = $state(0);
170
+
> let thing = {
171
+
> toString() {
172
+
> return count;
173
+
> }
174
+
> };
175
+
> </script>
176
+
> <button onclick={() => count++}>Count is {thing}</button>
177
+
> ```
178
+
> In the above case, if you wanted the statement to be reactive, you would have to append `.toString()` to the expression (to turn `{thing}` into `{thing.toString()}`).
0 commit comments