SimCoderYoutube / InstagramClone

Instagram Clone React Native Tutorial 2021 👨‍💻 I'll show you how you can do this in the simplest way and terms possible. By the end of this series you'll have learned how the big companies do it and will be able to do the same, you not only will be able to do this app, but you'll be able to put what you learn into your very own projects! In this series, we use React Native with Expo to quickly deploy the project. We use firebase for all our microservice needs like the auth system, database, storage, amongst others. firebase, redux, react native, javascript, expo. In this series, we'll use all of them and you'll learn them by doing an iconic app. Welcome to this Simcoder project and make an Instagram Clone!
Apache License 2.0
745 stars 294 forks source link

Possible Unhandled Promise Rejection when trying to render the Feed #16

Open coding-st opened 3 years ago

coding-st commented 3 years ago

Hi,

I'm getting the following error when opening the Feed Screen:

Possible Unhandled Promise Rejection (id: 0): TypeError: undefined is not an object (evaluating 'snapshot.query.EP.path')

The Feed also won't render because of that. The code line which produces the error is in the action index.js the const ui:

export function fetchUsersFollowingPosts(uid) {
    return ((dispatch, getState) => {
        firebase.firestore()
            .collection("posts")
            .doc(uid)
            .collection("userPosts")
            .orderBy("creation", "asc")
            .get()
            .then((snapshot) => {
                const uid = snapshot.query.EP.path.segments[1];
                const user = getState().usersState.users.find(el => el.uid === uid);
                let posts = snapshot.docs.map(doc => {
                    const data = doc.data();
                    const id = doc.id;
                    return { id, ...data, user }
                })

                for(let i = 0; i< posts.length; i++){
                    dispatch(fetchUsersFollowingLikes(uid, posts[i].id))
                }
                dispatch({ type: USERS_POSTS_STATE_CHANGE, posts, uid })

            })
    })
}

Can anybody support?

SimCoderYoutube commented 3 years ago

Hi @coding-st !

Thank you for your participation.

I'll be reviewing that bug and I'll try to push out a fix for it asap :)

coding-st commented 3 years ago

@SimCoderYoutube thanks for your fast reaction. Your tutorials are awesome! Looking forward to hear from you.

cyber-portfolio commented 3 years ago

Has any found a fix to this?

cerovcecblaze commented 3 years ago

A potential solution is to use this:

const uid = snapshot.docs[0].ref.path.split('/')[1];

and put that line^ and the rest of the code in that function in a try catch block. The line above will throw an error if there is no documents (posts), so for users where this throws an error, just catch, and do nothing since its pointless to get the posts of a user with no posts.

minhquan0902 commented 3 years ago

I think you should console.log(snapshot) for yourself and try to find the segments data based on the console.log, the snapshot data might be different because firebase might update their way to display the snapshot. For my part i was able to retrieve the data from snapshot..query.C.path.segments[1];

MQ-test commented 2 years ago

I encountered this error while following the video. What does the EP mean? I had google around for documentation, and could not find any reference to this