I have a component that I have created:
class Create extends Component {
  constructor(props) {
    super(props);
  }
  render() {
    var playlistDOM = this.renderPlaylists(this.props.playlists);
    return (
      <div>
        {playlistDOM}
      </div>
    )
  }
  activatePlaylist(playlistId) {
    debugger;
  }
  renderPlaylists(playlists) {
    return playlists.map(playlist => {
      return <div key={playlist.playlist_id} onClick={this.activatePlaylist(playlist.playlist_id)}>{playlist.playlist_name}</div>
    });
  }
}
function mapStateToProps(state) {
  return {
    playlists: state.playlists
  }
}
export default connect(mapStateToProps)(Create);
When I render this page, activatePlaylist is called for each playlist in my map.  If I bind activatePlaylist like:
activatePlaylist.bind(this, playlist.playlist_id)
I can also use an anonymous function:
onClick={() => this.activatePlaylist(playlist.playlist_id)}
then it works as expected. Why does this happen?
 
     
     
     
     
     
    