Object passed as prop gets changed in parent component when change is made in child component

Viewed 154

I'm new to vue.js and up until today I thought props are one-way bound. But today I understood if we pass an object as a prop it gets passed by reference, therefore, changes we do in child component propagate back to the parent. What I actually did was something like this:

const studentObj = ref(props.initialStudentObj)

And then the changes I did to studentObj in child component propagated back to the parent and the initialStudentObj value in parent component got changed.

I know mutating props in child components is an anti-pattern, so I want to know what is the most recommended way of doing this.

0 Answers
Related