Subscribe on changes!

Pass prop name in watch callback

avatar
Oct 17th 2020

What problem does this feature solve?

This helps in adding dynamic watchers for dynamic component data

What does the proposed API look like?

watch (
()=> dataObject['propA'],
(prop, newValur, oldValue) =>{},
options
)
avatar
Oct 18th 2020

try this?

watch(
  toRef(dataObject, 'propA'),
  ...
)
avatar
Oct 18th 2020

There isn't always a name property to be passed but you can do that by using an array:

const name = ref('dynamic name')
const object = reactive({})

watch(() => [name.value, object[name.value]], ([newName, newValue]) => {})
avatar
Oct 18th 2020

try this?

watch(
  toRef(dataObject, 'propA'),
  ...
)

propA is dynamic. Unknown until runtime.