Last active
August 16, 2018 17:42
-
-
Save maecapozzi/759a6138f2f434588922dc36ae4b52ab 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
import React from "react"; | |
import { FamilyProvider, FamilyConsumer } from "./FamilyContext"; | |
export class Grandmother extends React.Component { | |
state = { | |
lastName: "Sanchez" | |
}; | |
render() { | |
return ( | |
// We wrap all of the components that need access | |
// to the lastName property in FamilyProvider. | |
<FamilyProvider value={this.state.lastName}> | |
<Mother /> | |
</FamilyProvider> | |
); | |
} | |
} | |
const Mother = () => { | |
return <Child />; | |
}; | |
const Child = () => { | |
// We wrap the component that actaully needs access to | |
// the lastName property in FamilyConsumer | |
return <FamilyConsumer>{context => <p>{context}</p>}</FamilyConsumer>; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment