Files
react-navigation/packages/core/src/StaticContainer.tsx
Abhinandan Ramaprasath 2bf0958502 fix: static container memo check (#6825)
Memo check compared elements of prevProps to nextProps but failed
to take new props into account. Fixed the logic and added a new
test.
2020-02-12 10:56:23 +01:00

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;
});