I am working on a React JS application, which is a match score predicting app.
With the following code the app currently displays a list of upcoming matches for which the user can click on and enter a prediction.
if(!this.props.loading && !this.props.error){
upcomingmatches = this.props.upcmgMatches.map(upcomingMatch => {
    return <UpcomingMatch
        key={upcomingMatch.id}
        teamA={upcomingMatch.teamA}
        teamB={upcomingMatch.teamB}
        matchKickoff={upcomingMatch.matchKickoff}
        clicked={() => this.addInitInputMatchResultHandler(upcomingMatch.id, upcomingMatch.teamA, upcomingMatch.teamB, upcomingMatch.matchKickoff)}
    />
});
}
I want to modify it so that if a user has already made a prediction for a match then it will display the component but with additional info e.g. their current predictions.
My component has access to two object arrays which are received from a Firebase table and turned into arrays.
upcmgMatches shows all the current upcoming matches that a user can make a prediction for.
userPredictions shows all the matches that the user had made predictions for that have still not been played. So this could include all matches in upcmgMatches if they've made predictions for all of them or just a subset of these matches or I guess an empty array if they haven't made any predictions.
These arrays are shown below.
So id from upcmgMatches should be matched with matchID in userPredictions
upcmgMatches = [{
    "matchKickoff": "2018-09-22T10:45",
    "teamA":"Roosters",
    "teamB":"Dragons",
    "id":"-LN-pNFv-rFJQkunM1Tv"
  },  
  {
    "matchKickoff": "2018-09-22T19:00",
    "teamA": "Storm",
    "teamB": "Sharks",
    "id": "-LMrXWzcEjN_u_jlULuJ"
  }]
userPredictions = [{
    "matchID": "-LMrXWzcEjN_u_jlULuJ",
    "teamAName": "Storm",
    "teamAScore": "22",
    "teamBName": "Sharks",
    "teamBScore": "12",
    "userId": "J2QO4OHT5vc7aAkT9vcdREo1IuW2",
    "id": "-LMvzSoaMAhBUhgWMOpM"
  }]
So I think my modified logic would be ..
For each match in upcmgMatches, check whether the id exists in userPredictions on the matchID field, if it does then return the UpcomingMatch component with the additional info from userPredictions namely TeamAScore and teamBScore. If it doesn't then just return the info from upcmgMatches, which should be the same but without predicted scores.
 
     
    