Problem Statement
What is watchEffect() and how is it different from watch()?
Explanation
watchEffect runs a reactive effect immediately and tracks dependencies automatically based on what it reads, no need to declare a specific source. watch watches explicit sources and gives new/old values. Use watchEffect for quick reactive side effects; use watch when you need precise control and values.
Code Solution
SolutionRead Only
import { watchEffect } from 'vue'
watchEffect(() => {
// any reactive reads here become dependencies
console.log('User:', state.user.name)
})