svelte
svelte copied to clipboard
More documentation about non working reactivity
Describe the bug
I often hear from other developers having issues with reactive statements doing nothing. For instance:
<script>
export let data; // We use sveltekit
$: me = data.me;
$: hasThing = me.things.length > 0
setContext('hasThing', hasThing); // hasThing is always undefined??
</script>
This won't work, and this behavior is documented:
https://svelte.dev/docs#component-format-script-3-$-marks-a-statement-as-reactive
I feel that this documentation is a bit underwhelming considering how often I hear about this problem.
What could help:
- A compiler warning
- A dedicated tutorial page
- A dedicated block in the documentation, around https://svelte.dev/docs#component-format-script-3-$-marks-a-statement-as-reactive
- An eslint rule
- You name it
Reproduction
Logs
No response
System Info
-
Severity
annoyance