Search code examples
javascriptreactjsreact-reduxjavascript-objectsreact-redux-firebase

FirestoreConnect returns nested object, having trouble picking out the data


I have a firebase database with subcollections, I've successfully gotten the data and can see it in the console, but not sure how to pick out the array that I need out of the received data. my call to the db collection:

export default compose(
    connect(mapStateToProps),
    firestoreConnect([
        {
            collection: 'team',
            doc: "CHSFG8Y7UrcWAbtL1HaUqjxYRyf1", 
            subcollections: [
                { collection: 'rss' }
            ]
        }
    ])
)(Dashboard);

Here is the console output (state.firestore.ordered):

{team: Array(1)}
  team: Array(1)
    0:
      id: "CHSFG8Y7UrcWAbtL1HaUqjxYRyf1"
      rss: (132) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, ...]
      __proto__: Object
      length: 1
      __proto__: Array(0)
      __proto__: Object

cleaned up version:

{"team":[{"id":"CHSFG8Y7UrcWAbtL1HaUqjxYRyf1","rss":[
{"id":"05oQ5nVGnyvOKY09zBgD", "sector":"2","x":"354","y":"578"}, 
{"id":"07VU6kLzhXTeFnIIU1PK", "sector":"7","x":"91","y":"131"}, 
{"id":"1IbN7IfveOPRI3sPOEDF", "sector":"7","x":"195","y":"190"}
]

basically I want the rss array as my data. I've tried state.firestore.ordered.team, which gets me down to the next level, but can't get to the rss array... thoughts?? I just need that rss array, then I can map the data in my project. state.firestore.ordered.team.rss doesn't work, gives me an error:

Cannot read property 'rss' of undefined

Solution

  • Hello my friend you might wanna try to use this form to access what you want:

    1. getting data from state.firestore.data: collection[document].subCollection
    2. getting data from state.firestore.ordered: collection[0].subCollection