How to Watch Props Change with Vue Composition API / Vue 3?

This guide shows how to monitor and respond to prop changes in Vue 3 using watch() with toRef() or toRefs() effectively.

Summarize with AI

Not enough time? get the key points instantly.

In Vue 3’s Composition API, watching for prop changes is essential when you need to respond to updated values passed from a parent component. Unlike Vue 2, you no longer use watch: {} in the options API but instead use the watch() function with toRefs() or toRef().

How to Watch Props in Vue 3 Composition API

To reactively watch a prop, use the watch() function inside the setup() method. Vetted VueJS developers use props to be wrapped with toRef() or toRefs() to retain reactivity.

Using toRef()

Using toRefs()

Common Gotchas

Destructuring props without toRefs() or toRef() breaks Vue’s reactivity system. Use toRefs(props) for multiple props or toRef(props, ‘key’) for a single prop to keep reactivity intact.

Key Takeaway

In Vue 3 Composition API, use watch() with toRef() or toRefs() to track prop changes reactively. This helps you respond to parent-driven updates within components.

Related Resources


Resources

Insights from our engineering leaders.

Our team shares practical insights on the technologies and engineering decisions shaping enterprise software today, grounded in real client work.

Vue

Vue is Not a Constructor

Why You See "Vue is Not a Constructor" This error usually occurs when you're trying to use new Vue() to create an instance, but: Vue…