Answer the question
In order to leave comments, you need to log in
How to update render when state redux updates?
There is the following code
import React,{Component} from "react"
import {connect} from "react-redux"
class Aside extends Component{
renderAside(){
const asideItems = this.props.cart
console.log(asideItems) // Not Working never
return asideItems.map((item, key) =>{
return(
<div className="aside-item" key={key}>
<div className="aside-item__name">{item.product.name}</div>
</div>
)
})
}
render(){
return (
<div>
{this.renderAside()}
</div>
)
}
}
const mapStateToProps = (state) => {
console.log(state.asideReducer.cart) // Working when updated cart
return{
cart: state.asideReducer.cart
}
}
export default connect(mapStateToProps)(Aside)
Answer the question
In order to leave comments, you need to log in
The component should render automatically. If not, apparently, your state.asideReducer.cart does not change, but mutates. In this case, even if the data in the object has changed, the reference to the object remains the same, the editor does not see the change and does not redraw the component.
In short, show your reducer)
Looked at a couple of your questions.
Do you do everything at random?, and then go to the toaster?
Read the documentation, you are sculpting complete nonsense, I don’t want to offend you, but seriously, what was the last question about this one, did you read something about react, redux, at least the Getting Started section of the dock went through?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question