Last active
May 22, 2019 17:46
-
-
Save Tiagoperes/938f7b61371f3d51b5ab80215ee3a079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const findMovieById = (catalog, id) => find(catalog.data, { id: parseInt(id) }) | |
class Movie extends PureComponent { | |
componentDidMount() { | |
const { loadCatalog } = this.props | |
loadCatalog() | |
} | |
render() { | |
const { catalog, { match: { params: { id } } } = this.props | |
const movie = findMovieById(catalog, id) // the id of the movie is passed through a url parameter | |
if (isPristine(catalog)) return null | |
if (isLoading(catalog)) return <Loading /> | |
if (hasLoadError(catalog)) return <Error /> | |
return <Content movie={movie} /> | |
} | |
} | |
const mapStateToProps = ({ catalog }) => ({ catalog }) | |
const actions = { loadCatalog: resources.catalog.actions.load } | |
export default connect(mapStateToProps, actions)(Movie) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment