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

188
Visualizações
How do I convert this code from Firebase Firestore v8 to Firebase Firestore v9 Modular in React

I'm having trouble changing this code from firebase v8 to the modular version of firebase v9 in reactjs.

const uploadFirestore = useCallback(async() => {
  await db.collection('users').doc(res.user.uid).collection('tareas').add({
    name: 'Test Task',
    fecha: Date.now()
  })
})

And i want to convert it to firebase 9 modular, also pass the userUid in the collections.

I was trying making it this way:

import React, { useCallback } from 'react'
import { db } from "./firebase"
import { collection, doc, addDoc } from "firebase/firestore"; 

function App(props) {
  const uploadFirestore = useCallback(async() => {
    await addDoc(doc(db, 'users', props.user.uid, 'tareas'), {
      name: 'Test Task',
      fecha: Date.now()
    })
  })
  
  return (
    <div>
      <button onClick={uploadFirestore}>
        Upload
      </button>
    </div>
  )
}

export default App

This is my firebase.js:

import { initializeApp } from "firebase/app";
import { getFirestore } from 'firebase/firestore';


const firebaseApp = initializeApp({
    hidden api uwu
  });


const db = getFirestore(firebaseApp);

export { db }

But it throws a:

TypeError: n.indexOf is not a function

Any help?

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

0

This looks wrong:

addDoc(doc(db, 'users', props.user.uid, 'tareas'), ...

You're trying to add a document to a document, which has two problems:

  1. Documents can only be added to a collection, not to other documents.
  2. You're passing a path to a collection (tareas) to the call to doc.

What you want here is:

addDoc(collection(db, 'users', props.user.uid, 'tareas'), ...
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