Svelte · Senior · Question 69 of 75
What is a risk of using $state in a class field that is exposed as a public mutable property in a library?
- ✓Correct answer: Any consumer can mutate it, so invariants break; expose getters and methods and keep the state private (
#field = $state(...)) - 2Private fields can't be reactive
- 3Classes can't be used across components
Explanation
Private $state fields are supported and keep the API surface small.