# A Svelte prop is a getter, not an argument

- Published: 2026-11-28
- Tags: Why Svelte, Svelte
- URL: https://devtrillo.com/writing/why-svelte-6-props-are-getters/

> Part 6 of a series on Svelte in 2026. [Part 5](/writing/why-svelte-5-effect-escape-hatch/) 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:

```svelte title="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."[^bp] The fix is the rune from part 4:

```js
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):

```svelte title="App.svelte"
<script>
  import Badge from "./Badge.svelte";
  let type = $state("info");
</script>

<button onclick={() => (type = "danger")}>danger</button>
<Badge {type} />
```

```js title="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 Badge.** App 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.

## Declaring props

`$props()` returns the props, and you destructure them. The rest is plain JavaScript destructuring:[^props]

```svelte title="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.

```svelte title="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."[^props] 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."[^props] What happens when you do it anyway depends on what the parent passed. Pick a case:

**Who sees the write?** The child…

| The child | Child shows | Parent shows | Notes |
| --- | --- | --- | --- |
| reassigns a prop: count += 1 | the new value | the old value | A local override. The next time the parent changes count, the child takes the parent's value again. |
| mutates a plain object prop | the old value | the old value | Nothing happens. A plain object isn't reactive, and no warning tells you. |
| mutates a $state object prop | the new value | the new value | It works, and the dev build warns ownership_invalid_mutation: the child changed state it doesn't own. |
| writes a $bindable prop the parent bound | the new value | the new value | This is what $bindable is for. The parent opted in with bind:. |
| writes a $bindable prop the parent didn't bind | the new value | the old value | $bindable means the parent can bind, not that it must. Unbound, it's an override like any other prop. |
| writes a prop the parent bound without $bindable | the new value | the old value | No runtime error since 5.17.1. svelte-check flags the bind: in the parent. |
| calls a callback prop: onchange(value) | the new value | the new value | 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."[^props]

## The door back up

`$bindable` marks a prop the parent is allowed to bind:[^bindable]

```svelte title="FancyInput.svelte"
<script>
  let { value = $bindable(), ...props } = $props();
</script>

<input bind:value {...props} />
```

```svelte
<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."[^bindable] 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.[^bind]

**Quiz:** 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?

- 8
- 3
- 5

**Answer:** 5 — The override is temporary. The parent's getter now returns 5, and the child shows it.

- Not "8": The child's three clicks were never added to anything. They replaced the value locally, and the parent's write replaces it again.
- Not "3": That's React's useState(count) copy, which ignores later props. A Svelte override only lasts until the parent's next change.

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

- The field starts empty, using the fallback
- It throws props_invalid_value
- text becomes '' in the parent

**Answer:** It throws props_invalid_value — "Cannot do bind:value={undefined} when value has a fallback value." Start the parent's state at '' instead.

- Not "The field starts empty, using the fallback": The fallback only applies when the prop isn't bound. Bound to undefined, Svelte can't tell which value should win.
- Not "text becomes '' in the parent": The child doesn't push its fallback up. It throws before that can happen.

## 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."[^passing] 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."[^structure] 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."[^lift] 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,[^changelog] 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."[^bind]

**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`.[^props]

## 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`](https://svelte.dev/docs/svelte/$props) page; most of this post's rules come from it.[^props] The component section of [`bind:`](https://svelte.dev/docs/svelte/bind#bind:property-for-components) covers the fallback rule.[^bind]

Next: snippets, the replacement for slots.

[^props]: Svelte docs, [`$props`](https://svelte.dev/docs/svelte/$props).

[^bindable]: Svelte docs, [`$bindable`](https://svelte.dev/docs/svelte/$bindable).

[^bind]: Svelte docs, [`bind:`](https://svelte.dev/docs/svelte/bind). Function bindings need 5.9.0 or newer.

[^bp]: Svelte docs, [Best practices](https://svelte.dev/docs/svelte/best-practices).

[^changelog]: [Svelte changelog](https://github.com/sveltejs/svelte/blob/main/packages/svelte/CHANGELOG.md), 5.17.1: "remove bindable prop validation" ([#14946](https://github.com/sveltejs/svelte/pull/14946)). `$props.id()` arrived in 5.20.0 ([#15185](https://github.com/sveltejs/svelte/pull/15185)).

[^passing]: React docs, [Passing Props to a Component](https://react.dev/learn/passing-props-to-a-component).

[^structure]: React docs, [Choosing the State Structure](https://react.dev/learn/choosing-the-state-structure#don-t-mirror-props-in-state).

[^lift]: React docs, [Sharing State Between Components](https://react.dev/learn/sharing-state-between-components).

- **Part 7 — In Svelte 5, children is a function**: snippets, the replacement for slots: markup you declare, pass as a prop, type, and render with live arguments
