Created
September 13, 2019 21:27
-
-
Save andregardi/4edff51e37ea08a448921ee26151f6f2 to your computer and use it in GitHub Desktop.
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
| const UserContext = React.createContext(); | |
| const App = () => { | |
| const username = "John Doe"; | |
| const otherData = {}; | |
| return ( | |
| <UserContext.Provider value={{ username, otherData }}> | |
| <Header /> | |
| </UserContext.Provider> | |
| ); | |
| }; | |
| const Header = () => { | |
| return <Menu />; | |
| }; | |
| const Menu = () => { | |
| return <User />; | |
| }; | |
| const User = () => { | |
| const { username } = React.useContext(UserContext); | |
| return <h1>{username}</h1>; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment