Last active
July 13, 2019 09:02
-
-
Save zoozalp/188dfabcc5c8fd9f4405be443089fcfe to your computer and use it in GitHub Desktop.
Hoist Non-React Static
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 from 'react'; | |
import hoistNonReactStatic from 'hoist-non-react-statics'; | |
import Context from './Context'; | |
function withInAppNotification(WrappedComponent) { | |
class Enhanced extends React.PureComponent { | |
render() { | |
return ( | |
<Context.Consumer> | |
{showNotification => ( | |
<WrappedComponent | |
{...this.props} | |
showNotification={showNotification} | |
/> | |
)} | |
</Context.Consumer> | |
); | |
} | |
} | |
// Pass over static props | |
hoistNonReactStatic(Enhanced, WrappedComponent); | |
return Enhanced; | |
} | |
export default withInAppNotification; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment