Last active
March 26, 2019 22:57
-
-
Save alexandrzavalii/b3cc2efa243e1cff2d5fc53f3f73bc56 to your computer and use it in GitHub Desktop.
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
/* HOC for wrapping the component with Context Provider */ | |
const connect = Component => { | |
return function WrappedComponent(props) { | |
return ( | |
<CandyContext.Consumer> /* pass lollipops as a prop */ | |
{value => <Component {...props} lollipops={value} />} | |
</CandyContext.Consumer> | |
); | |
}; | |
}; | |
/* ChildComponent.js */ | |
const FirstChild = props => ( | |
<p> | |
I am John, and I am wearing {props.clothing} today. | |
{props.lollipops ? "thanks for lollipop" : "I want lolipop"} | |
</p> | |
); | |
/* subscribe FirstChild to Context Changes */ | |
export default connect(FirstChild); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment