D
D
DeniSidorenko2020-12-14 08:58:10
React
DeniSidorenko, 2020-12-14 08:58:10

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)


How can I make my renderer update when state.asideReducer.cart is updated? It is necessary to display the products that have been added to the basket. Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Egor Zhivagin, 2020-12-14
@DeniSidorenko

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)

A
alex4answ, 2020-12-14
@alex4answ

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 question

Ask a Question

731 491 924 answers to any question