I am trying to create some composables in a vue project to minimize code. This composable is intended to update/edit properties associated with specific documents within a collection. I have it working 80%, but the last 20% is:
updateDocs.js Composable:
import { ref } from "vue";
//firebase imports
import { db } from "../firebase/config";
import { doc, setDoc } from "firebase/firestore";
const updateWorks = () => {
const error = ref(null);
const updateWork = async (collection, targetID, property, updatedValue) => {
try {
console.log(collection, targetID, property, updatedValue);
const docRef = doc(db, collection, targetID);
console.log(docRef);
await setDoc(
docRef,
{
PROPERTY: updatedValue, <-even though I'm passing a property, it does not get picked up with the variable (question 1)
},
{ merge: true }
);
} catch (err) {
error.value = err.message;
}
};
return { updateDoc, error };
};
export default updateDocs;
editDocForm.vue component
<script>
//import composables
import updateDocs from "../../composables/updateDocs";
export default {
name: "EditDocForm",
setup() {
const { updateDoc } = updateDocs();
const handleDocUpdate = async (doc) => {
updateWork("collectionName", targetID,
propertyToUpdate, newPropertyValue);