Svelte · Senior · Question 58 of 75
What is wrong with deriving state from props like this in a reusable component?
let { initial } = $props();
let value = $state(initial);- ✓Correct answer:
valuecaptures only the initial prop; if it should keep syncing, use$derived(writable since 5.25) or a$bindableprop - 2Props can't be used as initial state
- 3It causes an infinite loop
Explanation
Sometimes capturing the initial value is intended (e.g. a form's default); then name it clearly, like initialValue.