Component - Firestore CRUD operations
This React Native component shows how to create, read, update, and delete data in Firestore. It displays a list of items from Firestore and lets users add new items, update existing ones, or remove them.
This React Native component shows how to create, read, update, and delete data in Firestore. It displays a list of items from Firestore and lets users add new items, update existing ones, or remove them.
View ├─ FlatList │ └─ renderItem: View │ ├─ Text │ ├─ Button (Update) │ └─ Button (Delete) ├─ TextInput └─ Button (Add Item)
collection() function do in Firestore when used in React Native?collection()collection() function points to a specific collection (group of documents) in Firestore.collection() = points to documents group [OK]addDoc function adds a new document to a collection.addDoc(collection(db, 'users'), data) which is the correct modern syntax.const docRef = doc(db, 'tasks', 'task1');
await updateDoc(docRef, {completed: true});
const docSnap = await getDoc(docRef);
console.log(docSnap.data());updateDoc call sets the field completed to true in the document 'task1'.getDoc fetches the updated document, so docSnap.data() returns the updated fields.const docRef = doc(db, 'notes', 'note1'); await deleteDoc(collection(db, 'notes', 'note1'));
deleteDoc function requires a document reference, not a collection reference.collection(db, 'notes', 'note1') which is invalid because collection() does not accept a document ID.getDoc to read the document and verify if 'age' exists and is less than 30.updateDoc to update the 'status' field without overwriting other data.Pass the test and this pattern moves unknown