import React from "react";
import { is } from "immutable";
export default class extends React.Component {
shouldComponentUpdate(nextProps = {}, nextState = {}) {
if (
Object.keys(this.props).length !== Object.keys(nextProps).length ||
Object.keys(this.state).length !== Object.keys(nextState).length
) {
return true;
}
for (const key in nextProps) {
if (!is(this.props[key], nextProps[key])) {
return true;
}
}
for (const key in nextState) {
if (!is(this.state[key], nextState[key])) {
return true;
}
}
return false;
}
}
// customEquals: lodash.isEqual、Immutable.is、dequal.deepEqual 等;
const useOriginalCopy = (value) => {
const copy = React.useRef();
const diffRef = React.useRef(0);
if (!customEquals(value, copy.current)) {
copy.current = value;
diffRef.current += 1;
}
return [diffRef.current];
};