mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-12-27 08:11:18 +01:00
This function accepts the component’s previous props, and its new props. It should return true if the old and new props are equal: that is, if the component will render the same output and behave in the same way with the new props as with the old. I need to use this function as state objects that are passed as props will always have different references.
18 lines
408 B
TypeScript
18 lines
408 B
TypeScript
import deepEqual from "deep-equal";
|
|
|
|
export const propsAreEqual = <T extends object>(
|
|
prevProps: T,
|
|
nextProps: T,
|
|
): boolean => {
|
|
for (const key in nextProps) {
|
|
if (typeof nextProps[key] === "object") {
|
|
if (!deepEqual(prevProps[key], nextProps[key])) {
|
|
return false;
|
|
}
|
|
} else if (!Object.is(prevProps[key], nextProps[key])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|