Skip to content

Instantly share code, notes, and snippets.

@andregardi
Created September 13, 2019 21:27
Show Gist options
  • Select an option

  • Save andregardi/4edff51e37ea08a448921ee26151f6f2 to your computer and use it in GitHub Desktop.

Select an option

Save andregardi/4edff51e37ea08a448921ee26151f6f2 to your computer and use it in GitHub Desktop.
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