Skip to content

Instantly share code, notes, and snippets.

@converge
Created October 16, 2019 21:01
Show Gist options
  • Save converge/17b0e6af33db67b47b974bbb231f17d1 to your computer and use it in GitHub Desktop.
Save converge/17b0e6af33db67b47b974bbb231f17d1 to your computer and use it in GitHub Desktop.
import React, { useContext } from 'react';
import logo from './logo.svg';
import './App.css';
const AppContext = React.createContext({ theme: null, nome: null });
function Post() {
const theme = useContext(AppContext);
return (
<div className="{theme}">
{console.log(theme)}
<h1>My posts</h1>
</div>
);
}
const Profile = () => {
const context = useContext(AppContext);
console.log(context.name);
return (
<div className="dados">
<p>Nome: {context.name} - {context.lastname}</p>
</div>
);
};
function App() {
return (
<div className="App">
<AppContext.Provider value="dark">
<Post />
</AppContext.Provider>
<AppContext.Provider value={ { name: "jp", lastname: "ok" }}>
<Profile />
</AppContext.Provider>
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment