Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda