diff --git a/src/TableRow.js b/src/TableRow.js index be5e8ff0..b5ddc1f7 100644 --- a/src/TableRow.js +++ b/src/TableRow.js @@ -1,12 +1,12 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { renderElement } from './utils'; +import { isPropsShallowEqual, renderElement } from './utils'; /** * Row component for BaseTable */ -class TableRow extends React.PureComponent { +class TableRow extends React.Component { constructor(props) { super(props); @@ -18,6 +18,10 @@ class TableRow extends React.PureComponent { this._handleExpand = this._handleExpand.bind(this); } + shouldComponentUpdate(newProps) { + return !isPropsShallowEqual(this.props, newProps); + } + componentDidMount() { this.props.estimatedRowHeight && this.props.rowIndex >= 0 && this._measureHeight(true); } diff --git a/src/utils.js b/src/utils.js index 94cacc6e..90fded3f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -62,6 +62,30 @@ export function isObjectEqual(objA, objB, ignoreFunction = true) { return true; } +const hasOwnProperty = Object.prototype.hasOwnProperty; +export function isPropsShallowEqual(objA, objB) { + if (objA === objB) return true; + if (objA === null || objB === null) return false; + if (typeof objA !== 'object' || typeof objB !== 'object') return false; + + const keysA = Object.keys(objA); + const keysB = Object.keys(objB); + if (keysA.length !== keysB.length) return false; + + for (let i = 0; i < keysA.length; i++) { + const key = keysA[i]; + const valueA = objA[key]; + if ( + (!hasOwnProperty.call(objB, key) || valueA !== objB[key]) && + (key !== 'style' || !isObjectEqual(valueA, objB[key])) + ) { + return false; + } + } + + return true; +} + export function callOrReturn(funcOrValue, ...args) { return typeof funcOrValue === 'function' ? funcOrValue(...args) : funcOrValue; }