Created
October 31, 2018 09:08
-
-
Save danakt/c421a262a68e9de988c75ab8a3d1ad44 to your computer and use it in GitHub Desktop.
Pure Component HOC
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
/** | |
* Wraps any React component (even functional) to PureComponent class | |
*/ | |
export const pureComponent = function<P>(Component: React.ComponentType<P>) { | |
return class extends React.PureComponent<P> { | |
static displayName = `pureComponent(${Component.displayName || Component.name})`; | |
render() { | |
return <Component {...this.props} />; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment