Skip to content

Commit c8f963a

Browse files
authored
docs: add note on destructured declarations (#12873)
1 parent e4b7304 commit c8f963a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

sites/svelte-5-preview/src/routes/docs/content/02-examples/01-universal-reactivity.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ We can encapsulate this logic in a function, so that it can be used in multiple
4848
```
4949

5050
> Note that we're using a [`get` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) in the returned object, so that `counter.count` always refers to the current value rather than the value at the time the `createCounter` function was called.
51+
>
52+
> As a corollary, `const { count, increment } = createCounter()` won't work. That's because in JavaScript, [destructured declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) are evaluated at the time of destructuring — in other words, `count` will never update.
5153
5254
We can also extract that function out into a separate `.svelte.js` or `.svelte.ts` module...
5355

0 commit comments

Comments
 (0)