Created
April 25, 2017 11:43
-
-
Save developit/6e518a2ea4f2da03b0a8e4a2f81bc362 to your computer and use it in GitHub Desktop.
PureComponent for preact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@developit why don't you make this part of preact so we can just do
import {PureComponent} from 'preact'