I am trying to iterate out a card component with details relating to specific object in each field from a database. I have the details in state but I want my component to list cards for each of the objects I have saved to the database. I have done similar on PHP but I am new to React.
Am I going about this the right way? I want to iterate out three cards per line (the grid for material UI is set-up correctly above this). In each of the fields I want it
<GridList
className="team"
key="Subheader"
cellHeight={360}
cols={3}
spacing={2}
>
**{{schoolList.length > 0: i=0: i++}
return (
<Grid item xs={6} sm={4}>
<Card className={classes.root}>
<CardHeader
avatar={
<Avatar aria-label="scubaSchool" className={classes.avatar}>
S
</Avatar>
}
action={
<IconButton aria-label="settings">
<MoreVertIcon />
</IconButton>
}
title= {this.state.schoolList.diveSchoolName[i]}
subheader= {this.state.schoolList.diveSchoolLocation[i]}
/>
<CardMedia
className={classes.media}
image="/static/images/cards/paella.jpg"
title="Scuba School"
/>
<CardContent>
<Typography variant="body2" color="textSecondary" component="p">
{this.state.schoolList.diveCertificatesOfferredID[i]}
</Typography>
</CardContent>
<CardContent>
<Typography variant="body2" color="textSecondary" component="p">
{this.state.schoolList.diveSpotsOfferredID[i]}
</Typography>
</CardContent>
<CardActions disableSpacing>
<IconButton aria-label="add to favorites">
<FavoriteIcon />
</IconButton>
<IconButton aria-label="share">
<ShareIcon />
</IconButton>
<IconButton
className={clsx(classes.expand, {
[classes.expandOpen]: expanded,
})}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon />
</IconButton>
</CardActions>
<Collapse in={expanded} timeout="auto" unmountOnExit>
</Collapse>
</Card>
</Glad>
)}
</GridList>
I am aware of the map method in javascript but how would specify the different property for each field?