Last active
January 28, 2017 02:04
-
-
Save johntran/0e41633fbdc2a96e0925f2d22bac6636 to your computer and use it in GitHub Desktop.
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 React, { Component } from 'react'; | |
import {isEqual} from 'lodash'; | |
import ProductDetails from 'client/ProductDetails'; | |
// Product Details is a React Component | |
function optimizeRendering(keys: Array<string>, Wrapped: React<Element>) { | |
return class OptimizedComponent extends Component { | |
shouldComponentUpdate(nextProps) { | |
const changedKeys = keys.filter(key => !isEqual(nextProps[key], this.props[key])); | |
return changedKeys.length > 0 | |
} | |
render() { | |
return (<Wrapped {...this.props}/>) | |
} | |
} | |
} | |
optimizeRendering(['shopNavOpen', 'containerWidth'], ProductDetails) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment