mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-06-11 00:09:17 +08:00
Memo check compared elements of prevProps to nextProps but failed to take new props into account. Fixed the logic and added a new test.
30 lines
613 B
TypeScript
30 lines
613 B
TypeScript
import * as React from 'react';
|
|
|
|
/**
|
|
* Component which prevents updates for children if no props changed
|
|
*/
|
|
function StaticContainer(props: any) {
|
|
return props.children;
|
|
}
|
|
|
|
export default React.memo(StaticContainer, (prevProps: any, nextProps: any) => {
|
|
const prevPropKeys = Object.keys(prevProps);
|
|
const nextPropKeys = Object.keys(nextProps);
|
|
|
|
if (prevPropKeys.length !== nextPropKeys.length) {
|
|
return false;
|
|
}
|
|
|
|
for (const key of prevPropKeys) {
|
|
if (key === 'children') {
|
|
continue;
|
|
}
|
|
|
|
if (prevProps[key] !== nextProps[key]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
});
|