Answer the question
In order to leave comments, you need to log in
How to make multiple stateful components on a page?
I'm just learning about Rect in conjunction with Redux, and naturally questions arise that are difficult to find answers on the Internet. The question is that there is a simple data structure in redux by type:
{
products : {
productList1:[{Product},{Product},{Product}],
productList2:[{Product},{Product},{Product}],
},
contacts : {
phone:'512-421-3940',
email:'[email protected]',
address:'1739 Bubby Drive',
content: "this is contacts page",
},
notFound:{},
}
import React from 'react';
import {connect} from 'react-redux';
import './style.css';
import ProductItem from './productItem';
const ProductList = ({productList})=>{
let products = productList.map((item,index)=>{
return(
<div class="col-sm-4">
<ProductItem product={item} key={index} />
</div>
);
});
return(
<div class="product-list">
<div class="container">
<div class="row">
<div class="product-list__header">
<h2 class="product-list__header__title">Pricing Table</h2>
</div>
{products}
</div>
</div>
</div>
);
}
export default ProductList;
Answer the question
In order to leave comments, you need to log in
Inside the connect function, you are subscribing to a piece of your store (that is, a piece of your application's entire state). It usually looks like this:
const mapStateToProps = state => ({ // state = все ваши редьюсеры, то есть тут лучше было бы писать store, но так уж поевелось..
campaigns: state.campaigns, // компонент подписывается только на state.campaigns (то есть только на редьюсер campaigns)
});
connect(mapStateToProps/*, mapDispatchToProps*/)(CampaignsList) // происходит коннект, mapDispatshToProps - это для "прокидывания" создателей действий (action creator)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question