Skip to content

vue-lost-reactivity ​

Reactive state read once where it should stay connected: destructuring a reactive() object, the props or a Pinia store; watching a value read from one (watch(props.id, ...)); or passing such a value to a composable (useUser(props.id)).

Why: Vue notices a change because it sees you read props.id when you read it. const { id } = props reads it once and keeps a plain copy, which never changes again. watch(props.id, ...) hands watch a string, not something it can watch, so the callback never runs. A composable given props.id gets today's id and never hears about the next one. TypeScript accepts the first and the last. Only vue-tsc refuses watch(props.id, ...) (no overload of watch takes a string or a number), and only where it runs. Guide: Vue.

vue
<script setup lang="ts">
import { reactive, watch } from "vue";
import { useCartStore } from "./stores/cart";

const props = defineProps<{ userId: string }>();
const form = reactive({ email: "", newsletter: false });
const { email } = form;
const { items } = useCartStore();

watch(props.userId, (id) => console.log(`user ${id}`));
</script>

<template>
  <p>{{ email }}: {{ items.length }} items</p>
</template>
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { reactive, toRefs, watch } from "vue";
import { storeToRefs } from "pinia";
import { useCartStore } from "./stores/cart";

const props = defineProps<{ userId: string }>();
const form = reactive({ email: "", newsletter: false });
const { email } = toRefs(form);
const { items } = storeToRefs(useCartStore());

watch(() => props.userId, (id) => console.log(`user ${id}`));
</script>

<template>
  <p>{{ email }}: {{ items.length }} items</p>
</template>

A composable that should follow a value takes a getter or a ref, and reads it with toValue. The caller writes useGreeting(() => props.name):

✓ Accepted0 diagnostics
ts
import { computed, type MaybeRefOrGetter, toValue } from "vue";

export function useGreeting(name: MaybeRefOrGetter<string>) {
  return computed(() => `Hello, ${toValue(name)}`);
}

What a composable is. A function that calls Vue's reactivity (ref, computed, watch, onMounted, provide, ...), a store or another useX(). That is what can keep the value it was given and miss the next one. A function named useX that does none of this (const useDatePicker = (value?: string) => value?.length) reads its argument once, like any function, and isn't reported. The checker looks at the function where it is declared, in this file or the one it is imported from; when it can't see the body (a package), it goes by the name.

Only calls made during setup are reported: in <script setup> itself or in a composable's body. Inside a computed, a watcher, a handler or the template, the call runs again with the value of the time, so nothing is lost:

✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { computed } from "vue";

const props = defineProps<{ name: string }>();

function useInitials(name: string): string {
  return name.split(" ").map((part) => part.slice(0, 1)).join("");
}

const initials = computed(() => useInitials(props.name));
</script>

<template>
  <p>{{ initials }}</p>
</template>

A prop that never changes. A page built for one record often hands props.record to a dozen composables. If the record really can't change for the component's life, make that true: key the component by it where it is used (<RecordPage :key="record.id" :record="record" />), so a new record mounts a new page. The rule can't see that, so the getter (() => props.record) is still the form it accepts; it costs nothing when the value never changes.

Allowed: destructuring in defineProps() itself (const { id } = defineProps<...>()), which Vue compiles to stay reactive. Destructuring a store's actions, markRaw(...) values and constants (const { router, go } = useNavigationStore()), when the checker can read the store's defineStore(...): those never change, so a copy is the same value. State, getters, refs, computeds and reactives in it are reported.

Quick fixes: Watch a getter (watch(() => props.id, ...)) · Pass a getter.

What the rule can't see: a value copied into a variable first (const id = props.id), values passed to functions that aren't named useX, and reactive objects it didn't see being made (returned from a function, passed in as a parameter). Stores are recognized by Pinia's naming, useXStore(). A store whose definition the checker can't read (from a package, or built by a factory) is reported for any destructuring: read its members from the store instead (const navigation = useNavigationStore(), then navigation.router).

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra