hmk run dev
파이어베이스 데이터 긁어오고 형식맞추기 본문
파이어베이스의 데이터를 긁어오고 이니셜 스테이트 값과 형식 맞추기
const getPostFB = () => {
return function (getState, dispatch, { history }) {
const postDB = firestore.collection("post"); // 콜렉션선택
postDB.get().then((docs) => {
// 가져오는 방법 문서참고 https://firebase.google.com/docs/firestore/query-data/get-data?authuser=0
docs.forEach((doc) => {
console.log(doc.id, doc.data());
let _post = {
id: doc.id,
...doc.data(), //파이어 베이스 데이터 이니셜 스테이트와 맞추기
};
let post = {
id: doc.id,
user_info: {
user_name: _post.user_name,
user_profile:
_post.user.profile,
user_id: _post.user_id,
},
image_url:
_post.image_url,
contents: _post.contents,
comment_cnt: _post.comment_cnt,
insert_dt: _post.insert_dt,
};
});
});
};
};
'React' 카테고리의 다른 글
async, await (0) | 2021.05.20 |
---|---|
쿠키방식 로그인 코드 (0) | 2021.04.17 |
1 쿠키 저장 삭제 (0) | 2021.04.01 |
파이어 베이스로 회원가입 기능 만들어주기 (0) | 2021.03.29 |
컴포넌트 쪼개기 + defaultProps (0) | 2021.03.29 |
Comments