Vue · Reactivity

VUE0034Derive state with computed() instead of a watcher

Finds watchers whose only effect is assigning a value derived from their sources to a local ref.

Why it happens

A ref fed by a watcher is a second copy of derived state. A watch() without immediate does not run until a source changes, and Vue skips it entirely during server rendering, so the ref keeps its initial value until then. Other watchers write the ref in a later flush, so code that reads it right after changing a source sees the old value. computed() derives the value on read, caches it, and cannot drift from its sources.

Fix

Replace the ref and the watcher with a computed(). This Rule is in the strict preset: a non-immediate watcher also skips its first run on the client, so server and client render the same initial value and the pattern is a design choice, not a hydration defect.

Example

Derive state with computed()

Before

<script setup lang="ts">
const count = ref(1)
const doubled = ref(0)
watch(count, (value) => {
  doubled.value = value * 2
})
</script>

After

<script setup lang="ts">
const count = ref(1)
const doubled = computed(() => count.value * 2)
</script>

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework vue --extends auto,vue/strict --rules vue/reactivity/prefer-computed-over-watch-assign
Copyright © 2026