'How to counter of likes with the data I get from Firebase?

I am using realtime database. I keep the userId of the users who like it. My goal is to take the number of them and import them into my application.

enter image description here

function getComments(){

  const user = firebase.auth().currentUser.uid;
  const db = firebase.database();
  const ref = db.ref('Post/');

  ref.once("value",snapshot=>{       
    if (snapshot.val()) {          
          const data=snapshot.val();
          const homePost=Object.values(data) || [];
          setList(homePost);     
    }
  } )
}

     <FlatList
        data={list}
        keyExtractor={(item)=>item.key}
        renderItem={({item,index})=>{
       return( 
</View>
    <Card.Divider/>    
    <View style={styles.detailsPostView}>
   
     <Text style={styles.detailsPostCountText}> //This section will get the number of likes.
       </Text>
          <Text style={styles.detailsPostText}>votes</Text>    
    </View>
  </Card>
           )
        }
      }
    />


Solution 1:[1]

If you want to know the number of child nodes in a snapshot, you can get that with snapshot.numChildren(). Also see the Firebase documentation on DataSnapshot.numChildren().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Frank van Puffelen