Skip to content

Instantly share code, notes, and snippets.

@danakt
Created October 31, 2018 09:08
Show Gist options
  • Save danakt/c421a262a68e9de988c75ab8a3d1ad44 to your computer and use it in GitHub Desktop.
Save danakt/c421a262a68e9de988c75ab8a3d1ad44 to your computer and use it in GitHub Desktop.
Pure Component HOC
/**
* 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