I am new to React. I am trying to associate an on-click handler to a component rendered in a loop in React, but am getting a prop undefined error. My code is as follows:
import React, { Component } from 'react';
import './ImageGallery.css';
class ImageGallery extends Component {
  constructor(props) {
    super(props);
    this.selectImage = this.selectImage.bind(this);
  }
  selectImage(e){
    console.log(e.target);
  }
  render() {
    return (
      this.props.images.map(function(e, i){
        return <img alt={i} key={i} src={e} className="thumbnail" onClick={this.selectImage}/>
      })
    )
  }
}
export default ImageGallery;
Unfortunately the documentation around lists and keys is not very supportive for my scenario, as it does not also cover events: https://reactjs.org/docs/lists-and-keys.htm
The error message is: Cannot read property 'selectImage' of undefined
 
     
     
    