React 강의 듣고 fireabase와 연동하여 블로그 제작중인데요.
App.js 에서
const getPost = () => {
dbService.collection("posts").onSnapshot((snapshot) => {
const postArray = snapshot.docs.map((doc) => ({
id: doc.id,
...doc.data(),
}));
setPostList(postArray);
});
};
라는 코드를 사용해서 블로그 글 목록을 받아오고 postList에 저장하고 props를 통해서 post에 전달해주는 식으로 코딩 했습니다.
Main을 통해서 post로 들어가면 글이 제대로 나오는데 post에서 새로고침을 누르면 데이터를 받아오기 전에 페이지가 랜더링되어 오류가 나옵니다.
오류 코드는 TypeError: Cannot read property 'Tage' of undefined입니다.
post 코드는 아래와 같습니다.
const Post = ({ postList }) => {
let { id } = useParams();
let post = postList.find((post) => post.id === id);
console.log(postList);
return (
{post.Tage}Frontend
{post.title}
"작성자"
{post.PostedDate}
);
};
로컬 스토리지를 사용하는 방법 뿐인지 궁금합니다.