Skip to content

Instantly share code, notes, and snippets.

@jruif
Forked from developit/purecomponent.js
Created May 24, 2017 17:47
Show Gist options
  • Save jruif/ed1d927ce6b1a4c59024c7fb5003784c to your computer and use it in GitHub Desktop.
Save jruif/ed1d927ce6b1a4c59024c7fb5003784c to your computer and use it in GitHub Desktop.
PureComponent for preact
import { Component } from 'preact';
export default class PureComponent extends Component {
shouldComponentUpdate(props, state) {
return !(shallowEqual(props, this.props) && shallowEqual(state, this.state));
}
}
function shallowEqual(a, b) {
for (let key in a) if (a[key]!==b[key]) return false;
for (let key in b) if (!(key in a)) return false;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment