Giter VIP home page Giter VIP logo

Comments (27)

digimbyte avatar digimbyte commented on August 30, 2024 4

Hi!

I have tried to emulate the problem without success. But I'm trying to push an update for this ASAP.

The problem arises because there is no documented way of getting the ID of each object from the querySnapshot when you get the doc using an onSnapshot query. This is the "hack" I found that allows this. I'll be trying to push an update for this week

I'm pretty sure you can get the ID from the document reference from the docs collection
snapshot.docs[0].ref.path.split('/')[1]

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024 4

well i got the answer from the internet you can check it out form stackoverflow
πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡πŸ‘‡
https://stackoverflow.com/a/68456060/14078264

from instagramclone.

cerovcecblaze avatar cerovcecblaze commented on August 30, 2024 1

A potential solution is to use:

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.

from instagramclone.

minhquan0902 avatar minhquan0902 commented on August 30, 2024 1

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];

from instagramclone.

digimbyte avatar digimbyte commented on August 30, 2024 1

that's because there is no such thing as 'id' on the user.

from instagramclone.

AmitSrour avatar AmitSrour commented on August 30, 2024

just figured out this is a repost of #16
from a week ago.
I'm going to leave this open in case I can find a solution / or to be able to merge a solution

from instagramclone.

cyber-portfolio avatar cyber-portfolio commented on August 30, 2024

Have you found any solutions?

from instagramclone.

SimCoderYoutube avatar SimCoderYoutube commented on August 30, 2024

Hi!

I have tried to emulate the problem without success. But I'm trying to push an update for this ASAP.

The problem arises because there is no documented way of getting the ID of each object from the querySnapshot when you get the doc using an onSnapshot query. This is the "hack" I found that allows this. I'll be trying to push an update for this this week

from instagramclone.

Yeghishe-Karapetyan avatar Yeghishe-Karapetyan commented on August 30, 2024

Guys have you solved this??

from instagramclone.

Yeghishe-Karapetyan avatar Yeghishe-Karapetyan commented on August 30, 2024

it gives an error friend
@digimbyte

from instagramclone.

zacharie85 avatar zacharie85 commented on August 30, 2024

i have the same problem

from instagramclone.

JoshValencia avatar JoshValencia commented on August 30, 2024

snapshot.docs[0].ref.path.split('/')[1]

This is the solution!!!! I am getting the UID now. Still had some errors with props.usersState.users but I think this is a different problem.

from instagramclone.

zacharie85 avatar zacharie85 commented on August 30, 2024

from instagramclone.

digimbyte avatar digimbyte commented on August 30, 2024

for reference, I run a Firebase Community on Discord - we had a user who had the same issue, the error proceeding is related to something else in the project.
https://discord.firebase.me/

from instagramclone.

zacharie85 avatar zacharie85 commented on August 30, 2024

from instagramclone.

chaitanya1731 avatar chaitanya1731 commented on August 30, 2024

Getting the same error :(

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024

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

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating 'snapshot.docs[0].ref')]
also give error
after using this code

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024

is there is any solution ??

from instagramclone.

digimbyte avatar digimbyte commented on August 30, 2024

That would only mean that you aren't actually retrieving any files, since it would be undefined. I think this issue is effectively closed - the project would need a patch to make this more standard and integrated.

from instagramclone.

digimbyte avatar digimbyte commented on August 30, 2024

not sure what you mean: I posted that same code above and you claimed it gave you errors and you then also posted it on SO?

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024

well you are right but this code snapshot.docs[0].ref.path.split('/')[1]; is not working for me without this
change
dispatch(fetchUserFollowingPosts(user.id))
to
dispatch(fetchUserFollowingPosts(user.uid))

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024

that's why i post this

from instagramclone.

gxanshu avatar gxanshu commented on August 30, 2024

yes that's right

from instagramclone.

Jenpaulino3 avatar Jenpaulino3 commented on August 30, 2024

Mine was snapshot.query._.C_.path.segments[1], definitely need to log snapshot and look for yourself.

from instagramclone.

olawalethefirst avatar olawalethefirst commented on August 30, 2024

Hi guys, while implementing this practice app, I also came across the section in code where we needed to extract the specific uid for each query by using 'const uid = snapshot.query.EP.path.segments[1]'. I however found that unnecessary, as closure in javascipt binds inner functions to outer functions lexical scope, ensuring they have access to parent function variables. Hence, referencing the uid variable means that we will always get the correct reference. Please read more about it in the attached link, I am open to corrections if I am getting it wrong, thanks. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures

from instagramclone.

Tolu-pr avatar Tolu-pr commented on August 30, 2024

well you are right but this code snapshot.docs[0].ref.path.split('/')[1]; is not working for me without this change dispatch(fetchUserFollowingPosts(user.id)) to dispatch(fetchUserFollowingPosts(user.uid))

Please where did you make the change as I don't seem to find this dispatch(fetchUserFollowingPosts(user.id)) line in my code, on;y dispatch(fetchUsersFollowingPosts(uid)) in the fetchUsersData function.

from instagramclone.

billlouis avatar billlouis commented on August 30, 2024

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];

Yeah, did this and it worked

from instagramclone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.