이것이 최선의 방법으로 간주됩니까? 또는 불필요한 재 렌더링을 방지하는 더 나은 솔루션이 있습니까?shouldComponentUpdate에서 lodash 사용
수천 개의 행을 렌더링하려고합니다. 각 행에는 많은 셀이 있습니다. 그러나 내 감속기 중 하나에서 관련 상태가 아니라면 병목 현상을 예방하는 데 꽤 어려움이 있습니다.
import React, { Component } from 'react'
import _ from 'lodash'
import Cell from './Cell'
export class Row extends Component {
shouldComponentUpdate (newProps) {
return !_.isEqual(newProps.item, this.props.item)
}
componentDidUpdate (prevProps, prevState) {
console.log('row is updated!')
}
render() {
const { item } = this.props
return (
<div className='rowek'>
{item.map((i, key) => <Cell key={key} item={i}/>)}
</div>
)
}
}
export default Row
@ 나는 유사한 구조를 가지고 있고 나뿐만 아니라 shouldComponentUpdate를 사용 (나는 당신의 국가의 디자인을 모른다). –
네, 정상입니다. React의 최신 버전을 사용하고 있다면, 이것을 정확하게 수행하는'class Row extends PureComponent'를 사용할 수 있습니다. – azium