Skip to content

Instantly share code, notes, and snippets.

@Tiagoperes
Last active May 22, 2019 17:46
Show Gist options
  • Save Tiagoperes/938f7b61371f3d51b5ab80215ee3a079 to your computer and use it in GitHub Desktop.
Save Tiagoperes/938f7b61371f3d51b5ab80215ee3a079 to your computer and use it in GitHub Desktop.
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