UNPKG

@gechiui/compose

Version:
43 lines (36 loc) 1.05 kB
import { createElement } from "@gechiui/element"; /** * GeChiUI dependencies */ import isShallowEqual from '@gechiui/is-shallow-equal'; import { Component } from '@gechiui/element'; /** * Internal dependencies */ import createHigherOrderComponent from '../../utils/create-higher-order-component'; /** * External dependencies */ /** * Given a component returns the enhanced component augmented with a component * only re-rendering when its props/state change */ const pure = createHigherOrderComponent(Wrapped => { if (Wrapped.prototype instanceof Component) { return class extends Wrapped { 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 createElement(Wrapped, this.props); } }; }, 'pure'); export default pure; //# sourceMappingURL=index.js.map