Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Retrieving doc().id from google firebase documents from individual components in react native

I have a screen that lists "tasks" all being the same component <TaskItem> just with different props sent to them.

Each <TaskItem> is created by iterating over documents in a Firestore database collection.

I want to access the doc().id of the individual when they are clicked.

My question is: How can I access the doc().id for each particular <TaskItem> after they are rendered? Is this doc().id somehow attached or stored with the <TaskItem> when it is created?

tasks1 retreives the tasks from the backend and creates an array to use map on

db.collection('users').doc(id).collection('tasks').onSnapshot((snapshot)=>{
          const tempTasks = [];
          snapshot.forEach(
             doc => {
                 tempTasks.push(doc.data());
             }
          )
          setTasks(tempTasks);
      });

Firestore Database structure

db.collection('users').doc(id).collection('tasks').doc().id

I Iterate, using map over 'tasks' and create a <TaskItem> for each 'tasks' item in the database. Is the doc().id for each stored with it or do I somehow have to manually access it?

<View style={styles.tasks}>
                    
                        {tasks1.map((task) => {
                            return (

                                <View style={{ margin: 4}}>
                                <TaskItem
                                    //PROPS
                                    notes={task.notes}
                                    reminder={task.reminder}
                                    name={task.name}
                                    assigned={task.assigned}
                                    tagName = {task.tag}
                                    profileImage={task.profileImage}
                                    color={task.color}
                                    changeModal={() => changeStateHandler()}
                                    onPress={()=>setTagClicked(!tagClicked)}
                                />
                                </View>
                            );
                        })}
                    </View>

I want to retrieve the ID underlined in red for each individual task as its selected

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After using .data(), your object only contains the fields which you have stored in Firestore. You can have both data and the document ID by adding a few lines, like this:

doc => {
  var newData = doc.data();
  newData.id = doc.id;
  tempTasks.push(newData);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!