Here is how I get the data:
Currently when I console.log(snapshotData.data);
I get an array of this:
what I want to get is editorState, blocks, 0, text. I tried to get it using snapshotData.data.editorState.blocks.[0].text
, and snapshotData.data.editorState.blocks.0.text
and it didn't work
again, I want to get this:
On Firestore it's says: editorState is map, blocks -> array, 0 -> map, text -> string
CodePudding user response:
Try
// if blocks is an Array
snapshotData.data.editorState.blocks[0].text
or
// if '0' is a key corresponding to the smaller object
snapshotData.data.editorState.blocks["0"].text
Update
According to the screenshot uploaded, blocks
is actually an array containing one single object.
You should use the first code block I provided, i.e.
snapshotData.data.editorState.blocks[0].text
CodePudding user response:
Fixed by using optional chaining
console.log(snapshotData?.data?.editorState?.blocks[0]?.text);