Skip to content

Instantly share code, notes, and snippets.

@bloodyowl
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bloodyowl/64a4f5349fce6f28e5ea to your computer and use it in GitHub Desktop.
Save bloodyowl/64a4f5349fce6f28e5ea to your computer and use it in GitHub Desktop.
import React, {Component} from "react"
import shallowEqual from "react/lib/shallowEqual"
/**
* example :
*
* import React, {Component, PropTypes} from "react"
*
* class MyComponent extends Component {
*
* static propTypes = {
* someProp : PropTypes.string,
* someOtherProp : PropTypes.string,
* }
*
* render() {
* return (
* <div>
* <SubComponent someProp={this.props.someProp} />
* <OtherSubComponent someOtherProp={this.props.someOtherProp} />
* </div>
* )
* }
* }
*
* export default PureRender(MyComponent)
*
*/
export default (Component) => {
class PureRender extends Component {
shouldComponentUpdate(nextProps) {
return shallowEqual(this.props, nextProps)
}
render() {
return <Component {...this.props} />
}
}
return PureRender
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment