UNPKG

@wordpress/compose

Version:
28 lines (27 loc) 962 B
// packages/compose/src/higher-order/pure/index.tsx import isShallowEqual from "@wordpress/is-shallow-equal"; import { Component } from "@wordpress/element"; import { createHigherOrderComponent } from "../../utils/create-higher-order-component"; import { jsx } from "react/jsx-runtime"; var pure = createHigherOrderComponent(function(WrappedComponent) { 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.js.map