Skip to content
Advertisement

Firebase Firestore returns [object Object] instead of instead of a plain object

I have a custom hook called useDocument.js below which fetches the data from a firestore collection via a specific ID. Why is it that it’s returning [object Object] instead of plain object.

I’ve tried accessing the name property and logging it to the console using document.name but throws up an error:

Uncaught TypeError: Cannot read properties of null (reading ‘name’)

But when I use JSON.stringify(document), I can see the object properties and values

from documents 2: {“name”:”Mark Dave Marquez”,”id”:”D68ogPwGLCeaOfoRZIBe”}

Home.js

JavaScript

useDocument.js

JavaScript

From the collection:

From the Firestore Database

Advertisement

Answer

Nevermind, this is because of the way I use console.log("documents 2: " + document); Forgot that the + sign converts the object into string thus the output would become [object Object].

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement