Is there a way to assign a new value to a reactive object without losing reactivity? If we have an object we expect to be re-assigned, is nesting within a ref the only option?
Making sure I understand the requirement - you arer asking how to do the following:
let reactiveObj = reactive({ /* ... */ })
// ...later:
reactiveObj = reactive({ /* ... a new reactive object ... */})
... but keep reactivity for the reassignment of reactiveObj?
Then yes, the wa to do that is to use a ref:
const reactiveObj = ref({ /* ... */ })
// ...later:
reactiveObj.value = reactive({ /* ... a new reactive object ... */})
Thank you! The idea is that I have some reference object that regularly needs reassigned with a different value. Something like "selectedItem". Wasn't sure if there was a better method.
Anyways, is wrapping the new value in reactive really necessary?
Instead of:
reactiveObj.value = reactive({ /* ... a new reactive object ... */})
Isn't this sufficient:
reactiveObj.value = { /* ... */}
Or is there something I'm missing?
Oh so you only want to reassign a property? That has always worked like you expect it and will work like that here as well of course