My goal is to assign Firestore data, passed through props, to a reactive proxy object in Vue. However, I am encountering an error that says:
Object is possibly 'undefined'.
(property) fireStoreData: Record<string, any> | undefined
To streamline my code, I want to use a forEach loop instead of directly assigning values one by one.
props: {
fireStoreData: Object,
}
...
setup(props){
...
const pageForm: { [key: string]: any } = reactive({
name: '',
address: '',
...
})
onMounted(() => {
Object.keys(pageForm).forEach(key => {
if(key in props.fireStoreData) // <-- error found here
pageForm[key] = props.fireStoreData[key] // <-- and here
})
})
})
...
}