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

112
Visualizações
Change only one specific value from dynamic input field

i need some help.

So i have:

 data.map( (doc) => { 
      return (
         <div>
             <div> {doc.name}</div>
             <div> {doc.age}</div>
         </div>
   )
})

This iterate some data from Firebase Firestore into the web page.

Then there's an input field to change the age.

const [age, setAge] = useState(1);

const handleSubmitAge = async () => {
   const ageRef = doc(db, "user", "docID")
   await updateDoc(ageRef, {
         age : age
     });
}

.....

<div>
     <TextField
        value={age}
        onChange={ e => setAge(e.target.value)}
     />
     <Button onChange={handleSubmitAge}>
        Submit Age
     </Button>
</div

If i want to change doc.age, how do i do that? If i just write it like above, then if there are 10 names, all names will have the same age.

How do i make a reference to the "docID" in that "age" input field so that only one specific age is updated one specific person (name)?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Solution:

Thank you Mr. Frank van Puffelen.

Firstly, i need to access the document id for each doc in data.map( (doc) => ... ). We can do that earlier when we fetch the data from Firestore

async () => {
            const q = query(collection(db, "collectionName"), where("category", "==", `${some condition here}`));
            const querySnapshot = await getDocs(q);
                querySnapshot.forEach((doc) => {
                setData(querySnapshot.docs.map((doc) => ({...doc.data(), id:doc.id})))
                })
        };

That id:doc.id is what gives us the document id. Also thank you for the youtube tutorial from PedroTech and Maksim Ivanov for showing how to get this document id.

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