A Svelte prop is a getter, not an argument

By Esteban Trillo7 min readWhy SvelteSvelte

The parent never hands over a value, only a getter; the child just keeps asking.
The parent never hands over a value, only a getter; the child just keeps asking.

Part 6 of a series on Svelte in 2026. Part 5 covered $effect. This part covers how values get into a component, and the one door back out.

This line is correct in React and wrong in Svelte:

Badge.svelte
<script>
let { type } = $props();
let color = type === "danger" ? "red" : "green";
</script>
<p>{type}: {color}</p>

I mounted it with type set to info, then had the parent switch it to danger. The paragraph went from info: green to danger: green. The template picked up the new type, and color kept the old answer.

The compiler saw it coming. Building the file prints state_referenced_locally: “This reference only captures the initial value of type. Did you mean to reference it inside a closure instead?” The best-practices page has this exact example and one rule for it: “Treat props as though they will change.”1 The fix is the rune from part 4:

let color = $derived(type === "danger" ? "red" : "green");

With that, the paragraph reads danger: red. To see why the first version can’t work, look at what the parent hands over.

What the parent passes

Here’s the parent, then both files compiled with Svelte 5.57.2 (production client build, trimmed):

App.svelte
<script>
import Badge from "./Badge.svelte";
let type = $state("info");
</script>
<button onclick={() => (type = "danger")}>danger</button>
<Badge {type} />
App.js and Badge.js (compiled, excerpt)
Badge(node, {
get type() {
return $.get(type);
},
});
export default function Badge($$anchor, $$props) {
let color = $$props.type === "danger" ? "red" : "green";
$.template_effect(() => $.set_text(text, `${$$props.type ?? ""}: ${color}`));
}

The parent doesn’t pass "info". It passes an object with a getter, and the getter reads the parent’s state every time it’s called. In the child, type stopped being a variable at all. The compiler rewrote every read of it to $$props.type.

Part 2 showed that a component’s script runs once. So color is computed once, from whatever the getter returned at mount. The template reads $$props.type inside an effect, so it reads again on every change. A prop is live wherever you read it from a closure: the template, a $derived, an effect, a handler. It’s frozen wherever you read it once.

What App hands BadgeApp passes Badge a $$props object with a getter, get type(), which reads App's state each time it's called. Inside the Badge group, two things read it. The template effect calls the getter on every change, so it stays live. The let color line calls it once, at mount, shown with a red dashed arrow, so it's frozen on the first value.Apptype = $state$$propsget type()Badgetemplate effectreads every changelet colorread once, at mount

Declaring props

$props() returns the props, and you destructure them. The rest is plain JavaScript destructuring:2

Card.svelte
<script lang="ts">
interface Props {
title: string;
size?: "sm" | "md";
class?: string;
}
let { title, size = "md", class: klass, ...rest }: Props = $props();
</script>
<div class={klass} {...rest}>{title}</div>

A fallback like size = "md" applies when the parent doesn’t pass the prop, “or the value is undefined.” In the lab, a parent passed undefined, then "cool", then undefined again, and the child showed happy, cool, happy. The fallback comes back whenever the value goes away.

Renaming (class: klass) is for props whose names are keywords. ...rest collects everything you didn’t name, which is how a wrapper passes placeholder or aria-label through to the element inside it. It replaces Svelte 4’s $restProps. You can also skip destructuring with let props = $props(): props.title compiles to $props.title and stays live, but you lose fallbacks and renames.

Compiled, Card looks like Badge. title has nothing special about it, so every read is $$props.title. A prop with a fallback becomes $.prop($$props, 'size', 3, "md"), a small function that knows about the fallback. The rest becomes $.rest_props(...) with a list of names to leave out.

Writing to a prop

The docs’ own example: a child that adds one to the count it was given.

Child.svelte
<script>
let { count } = $props();
</script>
<button onclick={() => (count += 1)}>clicks (child): {count}</button>

That compiles. The docs call it a temporary override, “useful for unsaved ephemeral state.”2 In the lab I clicked the child three times: child 3, parent 0. Then I clicked the parent’s button once, and both showed 1. The parent’s next change wins.

Reassigning is allowed. Mutating isn’t: “you should not mutate props unless they are bindable.”2 What happens when you do it anyway depends on what the parent passed. Pick a case:

The child…
Child shows
the new value
Parent shows
the old value
Notes
A local override. The next time the parent changes count, the child takes the parent's value again.
Child shows
the old value
Parent shows
the old value
Notes
Nothing happens. A plain object isn't reactive, and no warning tells you.
Child shows
the new value
Parent shows
the new value
Notes
It works, and the dev build warns ownership_invalid_mutation: the child changed state it doesn't own.
Child shows
the new value
Parent shows
the new value
Notes
This is what $bindable is for. The parent opted in with bind:.
Child shows
the new value
Parent shows
the old value
Notes
$bindable means the parent can bind, not that it must. Unbound, it's an override like any other prop.
Child shows
the new value
Parent shows
the old value
Notes
No runtime error since 5.17.1. svelte-check flags the bind: in the parent.
Child shows
the new value
Parent shows
the new value
Notes
The parent sets its own state and passes the new value down. Nobody writes state they don't own.

The second row is the nasty one. Pass object={{ count: 0 }} and have the child run object.count += 1: nothing updates, and nothing warns. The object isn’t $state, so there’s nothing to notify.

The third row is the one that seems fine. Pass a $state object and the mutation shows up on both sides. The dev build warns ownership_invalid_mutation anyway, because two components now write the same state and only one of them owns it.

The docs end the section with the rule: “don’t mutate props. Either use callback props to communicate changes, or — if parent and child should share the same object — use the $bindable rune.”2

The door back up

$bindable marks a prop the parent is allowed to bind:3

FancyInput.svelte
<script>
let { value = $bindable(), ...props } = $props();
</script>
<input bind:value {...props} />
<FancyInput bind:value={message} />

Now typing in the input updates message in the parent. In the lab, the bound copy showed typed in both places. A second copy, given value={message} without bind:, showed typed in the input and hello in the parent. Then the parent reset its state and both inputs showed it.

Both sides have to agree. The child says $bindable, the parent says bind:, and either one alone gets you an ordinary prop.

I rarely reach for it, and the docs agree. Binding “isn’t something you should do often — overuse can make your data flow unpredictable.”3 Most of the time a callback is clearer: the child calls onchange(value) and the parent sets its own state. Same result on screen, and the parent can see where every write comes from. I’d keep $bindable for components that really are inputs, like a text field, a date picker or a toggle, where bind:value reads the same as it does on an <input>.

Function bindings from part 5 work on components too. <FancyInput bind:value={() => name, (v) => (name = v.toLowerCase())} /> turned GRACE into grace, both in the parent and back in the input.4

A child runs count += 1 three times on a plain prop, so it shows 3 while the parent still has 0. Then the parent sets count to 5. What does the child show?

A TextField has let { value = $bindable('') } = $props(). The parent writes let text = $state(); and <TextField bind:value={text} />. What happens?

How React does it

React’s docs describe props in one line: “Props are read-only snapshots in time: every render receives a new version of props.”5 That’s the opposite design. The component is a function, the parent calls it again with new arguments, and const color = type === 'danger' ? ... in the body is correct because the body runs again.

React’s trap sits one step over. You copy a prop into state, useState(count), and the state ignores every later prop. React’s docs call this “mirroring” and say the state “is only initialized during the first render.”6 I ported the counter to React 19.3.1 with that copy: three child clicks gave 3, one parent click gave parent 1 and child still 3. In Svelte the same steps gave 1 and 1. Svelte’s override resets on the next change from the parent, and React’s copy never does.

There’s no bind: in React. Data goes up the way Svelte’s callback version does it: the parent owns the state and passes down value and onChange. React’s docs call that lifting state up and “one of the most common things you will do writing React code.”7 Svelte 5 made events work the same way. createEventDispatcher is deprecated, and a component’s events are callback props like onchange, as they are in React.

Gotchas

Copying a prop into $state freezes it. let draft = $state(value) warns state_referenced_locally, and in the lab it ignored the parent’s next value. If you want an editable copy that resets when the parent changes, use a writable $derived(value) (part 4). Mine showed the edit, then switched to the parent’s new value when that arrived.

bind: on a prop that isn’t $bindable. Svelte’s dev build used to throw bind_not_bindable. Version 5.17.1 removed that check,8 and in the lab the child’s writes stayed in the child with no warning. svelte-check still catches it in the parent: “Cannot use ‘bind:’ with this property. It is declared as non-bindable inside the component.”

A bound prop with a fallback can’t start as undefined. Svelte throws props_invalid_value; start the parent’s state at '' or whatever the empty value is. The fallback “only applies when the property is not bound.”4

Bindable fallbacks are proxies, plain ones aren’t. With object = $bindable({ count: 0 }) and no parent, mutating object.count updated the button. Without $bindable, the same fallback ignored it.

$props.id() isn’t a prop. It’s a per-instance ID (5.20+) that matches on the server and the client, for for and aria-labelledby.2

One direction, and one door

The parent hands the child a getter, and every rule above comes down to when you call it. Read it in a closure and it’s live. Read it once and it’s frozen, and the compiler tells you. Reassign it and you get a local override until the parent speaks again. If you want a write to reach the parent, either call a function the parent gave you or open the $bindable door on purpose, from both sides.

Read the “Updating props” section of the $props page; most of this post’s rules come from it.2 The component section of bind: covers the fallback rule.4

Next: snippets, the replacement for slots.

Footnotes

  1. Svelte docs, Best practices. ↩

  2. Svelte docs, $props. ↩ ↩2 ↩3 ↩4 ↩5 ↩6

  3. Svelte docs, $bindable. ↩ ↩2

  4. Svelte docs, bind:. Function bindings need 5.9.0 or newer. ↩ ↩2 ↩3

  5. React docs, Passing Props to a Component. ↩

  6. React docs, Choosing the State Structure. ↩

  7. React docs, Sharing State Between Components. ↩

  8. Svelte changelog, 5.17.1: “remove bindable prop validation” (#14946). $props.id() arrived in 5.20.0 (#15185). ↩

Piwi hands a single letter to the user at a mailbox; a small note reads no noise.

Get the next one in your inbox

One email when a post goes out, with its sketch. Nothing in between, and one link to leave.

Sign in faster next time?

Add a passkey and skip the email link. Your fingerprint, face or device PIN is enough.