Overview - Readonly props
What is it?
Readonly props in Svelte are properties passed from a parent component to a child component that the child cannot change. They allow data to flow downwards in a one-way direction, ensuring the child only reads the value without modifying it. This helps keep components predictable and easier to understand. The child component can use these props to display or react to data but must not alter them.
Why it matters
Readonly props exist to keep data flow clear and prevent bugs caused by unexpected changes in child components. Without readonly props, child components might change data that parents rely on, causing confusing behavior and making apps harder to maintain. This clear separation helps developers build reliable, easy-to-debug user interfaces where data changes happen in a controlled way.
Where it fits
Before learning readonly props, you should understand basic Svelte components and how props are passed. After mastering readonly props, you can learn about reactive statements, stores for shared state, and two-way binding for controlled inputs. Readonly props are a foundation for managing data flow in Svelte apps.