I am iteratively generating card components via db input (data). I am trying to figure out how to properly mapStatetoProps and mapDispatchtoProps for each card. Currently my addCard action is causing a TypeError as it says the addCard action is undefined.
My Reducer component has an initialState that contains a card array where I am trying to put all these cards.
There might be a solution that I am just missing, but I'd appreciate any suggestions.
class CardContainer extends React.Component {
renderCard(item) {
this.props.addCard(item); // <- this is where addCard gets called
return (
<CardTemplate
title={item.name}
address={item.address}
phone={item.phone}
hours={item.hours}
key={item.service_id}
/>
);
}
renderCards(cardData) {
return cardData.map(this.renderCard);
}
render() {
return <div className="Card_Container">{this.renderCards(data)}</div>;
}
}
const mapStateToProps = state => {
return {
service_id: {
name: state.rtS.rightMenu.cards,
title: state.rtS.rightMenu.cards,
address: state.rtS.rightMenu.cards,
hours: state.rtS.rightMenu.cards
}
};
};
const mapDispatchToProps = dispatch => {
return {
addCard: item =>
dispatch({
type: actionTypes.ADD_CARD,
payloadA: item.name,
payloadAd: item.address,
payloadP: item.phone,
payloadH: item.hours,
payloadS: item.service_id
})
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(CardContainer);
I probably have the addCard method written incorrectly or I don't have the mapStatetoProps return{} correct.