Skip to content

Instantly share code, notes, and snippets.

@luyx2412
Created March 22, 2018 13:48
Show Gist options
  • Save luyx2412/fefa791a8b478c6494ab9120f180e3fb to your computer and use it in GitHub Desktop.
Save luyx2412/fefa791a8b478c6494ab9120f180e3fb to your computer and use it in GitHub Desktop.
High PureComponent React Native (compare include function)
// 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