-
-
Save jeremeylduvall/49b1c734354d0a9f88d5e71a3d1a4aaa to your computer and use it in GitHub Desktop.
Display photos function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const photos = props.data.allWordpressPost.edges; | |
const displayPhotos = () => { | |
const photoArray = []; | |
let photoRow = []; | |
let count = 0; | |
photos.map( photo => { | |
if ( photo.node.featured_media ) { | |
photoArray.push( photo ); | |
} | |
} ); | |
return ( | |
photoArray.map( photo => { | |
if ( photoRow.length === 3 ) { | |
photoRow = []; | |
} | |
photoRow.push( photo ); | |
count++; | |
if ( photoRow.length === 3 ) { | |
return returnRow( photoRow, count ); | |
} else if ( photoArray.length - count === 0 ) { | |
return returnRow( photoRow, count ); | |
} | |
} ) | |
) | |
} | |
const returnRow = ( photos, count ) => { | |
return ( | |
<PhotoRow photos={ photos } key={ count } /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment