Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
NewComponent.WrappedComponent = ComponentToWrap;
NewComponent.displayName = `${hocName}(${getComponentName(ComponentToWrap)})`;
if (ComponentToWrap.propTypes) {
const copiedProps = {
...sloppy(ComponentToWrap.propTypes),
};
passedProps.forEach((propName) => {
delete copiedProps[propName];
});
const newPropTypes = {
...copiedProps,
...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
};
if (allowExtraProps) {
NewComponent.propTypes = newPropTypes;
} else {
NewComponent.propTypes = exact(newPropTypes);
}
} else if (!allowExtraProps) {
// Get "sloppy" propTypes before getting "exact" prop types in case
// the original prop types were already "exact"
NewComponent.propTypes = exact(sloppy(NewComponent.propTypes));
}
return hoistNonReactStatics(NewComponent, ComponentToWrap);
};
}
});
const newPropTypes = {
...copiedProps,
...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
};
if (allowExtraProps) {
NewComponent.propTypes = newPropTypes;
} else {
NewComponent.propTypes = exact(newPropTypes);
}
} else if (!allowExtraProps) {
// Get "sloppy" propTypes before getting "exact" prop types in case
// the original prop types were already "exact"
NewComponent.propTypes = exact(sloppy(NewComponent.propTypes));
}
return hoistNonReactStatics(NewComponent, ComponentToWrap);
};
}
return function hoc(ComponentToWrap, ...hocParams) {
const NewComponent = componentAndParamsToComponent(
ComponentToWrap,
...(factory ? factoryParams : hocParams),
);
NewComponent.WrappedComponent = ComponentToWrap;
NewComponent.displayName = `${hocName}(${getComponentName(ComponentToWrap)})`;
if (ComponentToWrap.propTypes) {
const copiedProps = {
...sloppy(ComponentToWrap.propTypes),
};
passedProps.forEach((propName) => {
delete copiedProps[propName];
});
const newPropTypes = {
...copiedProps,
...(NewComponent.propTypes && sloppy(NewComponent.propTypes)),
};
if (allowExtraProps) {
NewComponent.propTypes = newPropTypes;
} else {
NewComponent.propTypes = exact(newPropTypes);
}