Complete the code to import Firebase configuration into your React app.
import { initializeApp } from 'firebase/app'; const app = initializeApp([1]);
You need to pass the Firebase configuration object named firebaseConfig to initialize the app.
Complete the code to get a Firestore database instance in React.
import { getFirestore } from 'firebase/firestore'; const db = getFirestore([1]);
You must pass the initialized Firebase app instance app to getFirestore to access Firestore.
Fix the error in the React useEffect hook to fetch Firestore documents.
useEffect(() => {
const fetchData = async () => {
const querySnapshot = await getDocs(collection(db, [1]));
// process data
};
fetchData();
}, []);The collection name must be a string, so it should be wrapped in quotes like 'users'.
Fill both blanks to add a new document to Firestore with React.
import { collection, [1] } from 'firebase/firestore'; const addUser = async (user) => { await [2](collection(db, 'users'), user); };
setDoc without a document reference.You import and use addDoc to add a new document to a Firestore collection.
Fill all three blanks to update a Firestore document in React.
import { doc, [1] } from 'firebase/firestore'; const updateUser = async (id, data) => { const userRef = doc(db, 'users', [2]); await [3](userRef, data); };
setDoc instead of updateDoc when only updating fields.You import updateDoc, use the id variable for the document ID, and call updateDoc to update the document.