Created
March 22, 2018 13:48
-
-
Save luyx2412/fefa791a8b478c6494ab9120f180e3fb to your computer and use it in GitHub Desktop.
High PureComponent React Native (compare include function)
This file contains 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
// Author: @tomzaku from https://gist.github.com/tomzaku/ccda8d03b8a35c92025a84cd14d0369b | |
// import liraries | |
import React, { Component } from 'react'; | |
import _ from 'lodash' | |
// create a component | |
export const isEqualObjectIncludeFunction = (first, second) => { | |
return _.isEqualWith(first, second, (val1, val2) => { | |
// Compare include function | |
if (_.isFunction(val1) && _.isFunction(val2)) { | |
return val1.toString() === val2.toString(); | |
} | |
}) | |
} | |
export class HighPureComponent extends Component { | |
shouldComponentUpdate = (nextProps, nextState) => { | |
return !isEqualObjectIncludeFunction(nextProps,this.props) || !isEqualObjectIncludeFunction(nextState,this.state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment