@wordpress/compose
Version:
WordPress higher-order components (HOCs).
33 lines (32 loc) • 1.14 kB
JavaScript
// packages/compose/src/higher-order/pure/index.tsx
import { isShallowEqual } from "@wordpress/is-shallow-equal";
import { Component } from "@wordpress/element";
import deprecated from "@wordpress/deprecated";
import { createHigherOrderComponent } from "../../utils/create-higher-order-component/index.mjs";
import { jsx } from "react/jsx-runtime";
var pure = createHigherOrderComponent(function(WrappedComponent) {
deprecated("wp.compose.pure", {
since: "7.1",
alternative: "Use `memo` or `PureComponent` instead"
});
if (WrappedComponent.prototype instanceof Component) {
return class extends WrappedComponent {
shouldComponentUpdate(nextProps, nextState) {
return !isShallowEqual(nextProps, this.props) || !isShallowEqual(nextState, this.state);
}
};
}
return class extends Component {
shouldComponentUpdate(nextProps) {
return !isShallowEqual(nextProps, this.props);
}
render() {
return /* @__PURE__ */ jsx(WrappedComponent, { ...this.props });
}
};
}, "pure");
var pure_default = pure;
export {
pure_default as default
};
//# sourceMappingURL=index.mjs.map