Created
September 6, 2017 14:14
-
-
Save adamgruber/db0831ba7e9e0dfaceac5c73397be7fd to your computer and use it in GitHub Desktop.
HOC to turn a stateless functional component into an instance of a PureComponent
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
import { PureComponent } from 'react'; | |
/** | |
* PureComponent HOC. | |
* | |
* @param {Function} renderFn Stateless functional component | |
* @return {PureComponent} Component wrapped as PureComponent | |
*/ | |
module.exports = function asPureComponent(renderFn) { | |
const comp = class AsPureComponent extends PureComponent { | |
render() { | |
return renderFn(this.props); | |
} | |
}; | |
comp.displayName = `${renderFn.name}AsPureComponent`; | |
return comp; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment