import * as React from 'react'; import { Link } from 'react-router'; import { provide } from '../../TypedRedux'; import { ApplicationState } from '../../store'; import * as AlbumDetailsState from '../../store/AlbumDetails'; interface RouteParams { albumId: number; } class AlbumDetails extends React.Component { componentWillMount() { this.props.requestAlbumDetails(this.props.params.albumId); } componentWillReceiveProps(nextProps: AlbumDetailsProps) { if (nextProps.params.albumId !== this.props.params.albumId) { nextProps.requestAlbumDetails(nextProps.params.albumId); } } public render() { if (this.props.isLoaded) { const albumData = this.props.album; return

{ albumData.Title }

{

Genre: { albumData.Genre.Name }

Artist: { albumData.Artist.Name }

Price: ${ albumData.Price.toFixed(2) }

Add to cart

; } else { return

Loading...

; } } } // Selects which part of global state maps to this component, and defines a type for the resulting props const provider = provide( (state: ApplicationState) => state.albumDetails, AlbumDetailsState.actionCreators ).withExternalProps<{ params: RouteParams }>(); type AlbumDetailsProps = typeof provider.allProps; export default provider.connect(AlbumDetails);