Looping in JS

When you need to loop over a list of stuff. Uses an "arrow function" to do the looping. This is done for performance reasons. Props should be passed on the photo element.

class PhotoGrid extends React.Component {
  render() {
    return(
      <div className='photo-grid'>
        {this.props.posts.map((post, index) => <Photo {...this.props} key={index} index={index} post={post} />)}
      </div>
    )
  }
}

Last updated