bsl
Version:
基于React的框架和UI组件
21 lines (17 loc) • 542 B
text/typescript
export default function areEqual<T>(prevProps: T, nextProps: T, interceptor?: (key: keyof T) => boolean): boolean {
const keys = Object.keys(nextProps);
const length = keys.length;
for (let i = 0; i < length; i++) {
const k = keys[i] as keyof T;
if (interceptor && interceptor(k)) {
return false;
}
if (k === 'children') {
continue;
}
if (typeof nextProps[k] !== 'function' && k !== 'children' && nextProps[k] !== prevProps[k]) {
return false;
}
}
return true;
}