오늘도 인스타그램 클론 중입니다.
그러나 역시나 문제가 있죠 예제 코드는 파베 버전 8 이고 저는 파베 버전 9으로 진행중입니다.
문제되는곳은 여기
import React, { Component } from 'react'
import { Text, View } from 'react-native'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { fetchUser } from '../redux/actions/index'
export class Main extends Component {
componentDidMount() {
this.props.fetchUser();
}
render() {
const { currentUser } = this.props;
console.log(currentUser)
if(currentUser == undefined){
return(<View><Text>undefind</Text></View>)
}
return (
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text>{currentUser.email} is logged in</Text>
</View>
)
}
}
const mapStateToProps = (store) => ({
currentuser: store.userState.currentUser
})
const mapDispatchProps = (dispatch) => bindActionCreators({fetchUser}, dispatch);
export default connect(null, mapDispatchProps)(Main);
여기서 문제는 snapshot.data() 값을 가져오지 못하고 있는것 입니다.
const {currentUser} 이부분의 중괄호를 없에면 undefined는 피하지만 평션 그자체를 가져오게 됩니다.
그래서 문제는 저 actions/index.js 파일에 문제가 있을거라고 수정중입니다.
import { getFirestore, collection, doc, getDoc } from "firebase/firestore";
import { getAuth } from 'firebase/auth'
import { USER_STATE_CHANGE } from '../constants/index'
export function fetchUser () {
const db = getFirestore();
const auth = getAuth();
return (dispatch)=>{
getDoc(doc(db, 'users', auth.currentUser.uid))
.then((snapshot) => {
if(snapshot.exists){
dispatch({ type: USER_STATE_CHANGE, currentUser : snapshot.data() })
}else{
console.log('does not exist')
}
})
}
}
이렇게 작성이 되었는데 무었이 문제일까요....
'기록중' 카테고리의 다른 글
인스타그램 클론코딩 (react-native, firebase) 고민했던것 (0) | 2021.12.27 |
---|---|
오늘의 검색 코드 및 에러코드 (0) | 2021.12.27 |
오늘만난 에러코드 검색코드(python pandas, fierbase v9) (0) | 2021.12.23 |
인스타그램 클론 코드( expo.io 설치하기 ) (0) | 2021.12.22 |
오늘의 검색코드 및 에러코드 (0) | 2021.12.22 |