UNPKG

preact

Version:

Fast 4kb React-compatible Virtual DOM library.

25 lines (22 loc) • 755 B
import { Component } from 'preact'; import { shallowDiffers } from './util'; // Built in a factory so bundlers can drop it when unused function createPureComponent() { /** * Component class with a predefined `shouldComponentUpdate` implementation */ function PureComponent(p, c) { this.props = p; this.context = c; } PureComponent.prototype = new Component(); // Some third-party libraries check if this property is present PureComponent.prototype.isPureReactComponent = true; PureComponent.prototype.shouldComponentUpdate = function (props, state) { return ( shallowDiffers(this.props, props) || shallowDiffers(this.state, state) ); }; return PureComponent; } export const PureComponent = /* @__PURE__ */ createPureComponent();