-
-
Save jruif/ed1d927ce6b1a4c59024c7fb5003784c 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