이전에는 데이터를 리스트로 가져오는 법을 해봤었다.
이번에는 해당 게시글을 클릭 했을 때, 해당하는 게시글의 데이터만 가져와보자!
// firebase
import { collection, getDocs, query, where } from "firebase/firestore";
import { firebaseDb } from "../../../../firebase.config";
const condition = query(
collection(firebaseDb, boardType),
where("id", "==", boardId)
);
// fetch board detail data func
async function fetchBoardDetail(condition) {
const querySnapshot = await getDocs(condition);
querySnapshot.forEach((doc) => {
setBoardData(doc.data());
});
}
받은 데이터 값으로 다음과 같이 클릭한 게시글의 정보를 보는 창을 만들었다.