React/Redux rendering a list that's updating every second

后端 未结 5 879
生来不讨喜
生来不讨喜 2021-02-01 06:44

I have a react component that receives props from the redux store every second. The new state has an array that\'s different than the last array. To be specific, every second an

5条回答
  •  暖寄归人
    2021-02-01 07:09

    PureComponent will shallowly compare the props and state. So my guess here is that the items are somehow new objects than the previous passed props, thus the rerendering.

    I would advice, in general, to only pass primitive values in pure components :

    class MyList extends Component {
        render() {
            return (
                
    {this.props.myList.map((item, index) => ( //or it's alternative ))}
    ); } } //... class MyRow extends PureComponent { render() { const {id, name} = this.props; return (
    {id} - {name}
    ); } }

提交回复
热议问题