import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import TrackList from './TrackList' import * as albumActions from '../actions/albumActions' class Album extends React.Component{ constructor(props) { super(props); this.state = { album: false } } // on render componentDidMount(){ this.loadAlbum( this.props.params.id ); } // when props changed componentWillReceiveProps( nextProps ){ if( nextProps.params.id != this.props.params.id ){ this.loadAlbum( nextProps.params.id ); } } loadAlbum( id ){ let self = this; $.ajax({ method: 'GET', cache: true, url: 'https://api.spotify.com/v1/albums/'+id, success: function(album){ self.setState({ album: album }); } }); } renderAlbum(){ if( this.state.album ){ return (