What is the difference between component and container in react redux?
The components construct a piace of the view, so it should render DOM elements, put content on the screen.
The containers participate in the data elaboration, so it should "talk" with redux, because it will need to modify the state. So, you should include connect (react-redux) what it makes the connection, and the functions mapStateToProps and mapDispatchToProps :
.
.
.
import { connect } from "react-redux";
class myContainer extends Component {
}
function mapStateToProps(state) {
// You return what it will show up as props of myContainer
return {
property: this.state.property
};
}
function mapDispatchToProps(dispatch) {
// Whenever property is called, it should be passed to all reducers
return bindActionCreators({ property: property }, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(myContainer);