Skip to content

Instantly share code, notes, and snippets.

@zoozalp
Last active July 13, 2019 09:02
Show Gist options
  • Save zoozalp/188dfabcc5c8fd9f4405be443089fcfe to your computer and use it in GitHub Desktop.
Save zoozalp/188dfabcc5c8fd9f4405be443089fcfe to your computer and use it in GitHub Desktop.
Hoist Non-React Static
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