implemented redux for state management

This commit is contained in:
andres alcocer
2019-03-30 16:30:05 -04:00
parent 8e22fc06d2
commit b5a263e46a
25 changed files with 699 additions and 301 deletions

View File

@@ -0,0 +1,42 @@
import React, { Component } from 'react';
import { bindActionCreators } from "redux";
import { connect } from 'react-redux';
import { getMovieRows } from '../getMovie';
import { fetchComedyMovies } from '../store/actions/index';
class ComedyMovies extends Component {
componentWillMount() {
this.props.fetchComedyMovies();
}
render() {
let movies
// Call getMoviesRows function only when we get the data back
// from the API through redux
if (this.props.movies.data) {
const url = '/discover/tv?api_key=224ce27b38a3805ecf6f6c36eb3ba9d0&with_genres=35';
movies = getMovieRows(this.props.movies.data, url);
}
return (
<>
<h1 className="movieShowcase__heading">Comedy Movies</h1>
<div className="movieShowcase__container">
{movies}
</div>
</>
)
}
}
const mapStateToProps = (state) => {
return { movies: state.comedy }
}
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({ fetchComedyMovies }, dispatch)
}
export default connect(mapStateToProps, mapDispatchToProps)(ComedyMovies);