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

164
Visualizações
Objects are not valid as a React child (found: object with keys {seconds, nanoseconds}). (Firebase, React, Material Table)

I am attempting to store Firebase documents as an array of objects, set a component's state equal to that array, and then display the objects through a Material Table however am receiving the following error: "Objects are not valid as a React child (found: object with keys {seconds, nanoseconds}). If you meant to render a collection of children, use an array instead."

const getSamples = async (isAdmin, userID) => {
  initializeApp({
    apiKey: 'AIzaSyC64KY9UehoX2fk7Ugw2XNPvG4zZ7sSdsQ',
    authDomain: 'uno-genomics.firebaseapp.com',
    databaseURL: 'https://uno-genomics-default-rtdb.firebaseio.com',
    projectId: 'uno-genomics',
    storageBucket: 'uno-genomics.appspot.com',
    messagingSenderId: '351603848354',
    appId: '1:351603848354:web:e974a024da6b7e7472d3fb'
  });
  const db = getFirestore();

  const samples = [];
  if (isAdmin === true) {
    const querySnapshot = await getDocs(collection(db, 'samples'));
    querySnapshot.forEach((doc) => {
      const sample = {
        clientID: doc.get('clientID'),
        name: doc.get('name'),
        stage: doc.get('stage'),
        submissionDate: doc.get('submissionDate'),
        estimateCompletionDate: doc.get('estimateCompletionDate')
      };
      samples.push(sample);
    });
  } else {
    const querySnapshot = await getDocs(collection(db, 'samples'), where('clientID', '==', userID));
    querySnapshot.forEach((doc) => {
      const sample = {
        clientID: doc.get('clientID'),
        name: doc.get('name'),
        stage: doc.get('stage'),
        submissionDate: doc.get('submissionDate'),
        estimateCompletionDate: doc.get('estimateCompletionDate')
      };
      samples.push(sample);
    });
  }
  return samples;
};
const Dashboard = () => {
  const [samples, setSamples] = useState([]);

  const userID = localStorage.getItem('userID');
  if (localStorage.getItem('adminMode') === 'true') {
    getSamples(true, userID).then((values) => {
      setSamples(values);
    });
  } else {
    getSamples(false, userID).then((values) => {
      setSamples(values);
    });
  }

  return (
    <>
      <Helmet>
        <title> UNO COVID Resources Collection </title>
      </Helmet>
      <MaterialTable
        columns={[
          { title: 'Client ID', field: 'clientID' },
          { title: 'Name', field: 'name' },
          { title: 'Stage', field: 'stage' },
          { title: 'Submission Date', field: 'submissionDate' },
          { title: 'Estimated Completion Date', field: 'completionDateEstimate' }
        ]}
        data={samples}
        title="Samples"
      />
    </>
  );
};

I have been able to display an array of fake objects stored in the component's state through Material Table so the error must have something to do with the asynchronous accession of Firebase.

about 4 years ago · Juan Pablo Isaza
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