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

273
Visualizações
Firestore getDoc wont work when using pathSegments in react

I'm trying to do a very simple data load from firebase but it wont work when I use path segments in react

something very simple as

import { getFirestore, getDoc, getDocs, setDoc, doc, updateDoc, getCollection, collection } from "firebase/firestore";
import { firebaseConfig } from "config";

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const firestore = getFirestore(app);


getDoc(doc(firestore, 'collection', ['path','to','document']));

it will throw an exception

Uncaught (in promise) TypeError: n.split is not a function

how can i do to pass an array for that function?

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

0

The doc() doesn't take an array as param but path segments (strings). Try using the spread syntax on array as shown below:

getDoc(doc(firestore, 'collection', ...['path','to','document']));
// spread syntax here                ⬆


// Equivalent to:
getDoc(doc(firestore, 'collection', 'path', 'to', 'document'));

doc() function signature from the documentation:

export declare function doc(firestore: Firestore, path: string, ...pathSegments: string[]): DocumentReference<DocumentData>;
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