Created
January 14, 2019 17:05
-
-
Save rsheldiii/fd0cf9f9cfa6eb9d09be9ab2231052ba to your computer and use it in GitHub Desktop.
React Higher Order Component to manage constants on the context
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 React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
const ConstantContext = React.createContext({}); | |
const ConstantConsumer = ConstantContext.Consumer; | |
export const ConstantProvider = ConstantContext.Provider; | |
export const ConstantConnect = (Wrappee) => { | |
return class extends Component{ | |
render() { | |
return ( | |
<ConstantConsumer> | |
{context => { | |
return ( | |
<Wrappee constants={context} {...this.props} /> | |
); | |
}} | |
</ConstantConsumer> | |
); | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment