Created
January 27, 2020 10:15
-
-
Save alex-boom/cc2896659243ab1917b0d6aab6a8d5a1 to your computer and use it in GitHub Desktop.
useContext
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
import React, {useContext} from "react"; | |
import "./styles.css"; | |
const MyContext = React.createContext(); | |
export default function App() { | |
return ( | |
<MyContext.Provider value="Hello"> | |
<Child /> | |
</MyContext.Provider> | |
); | |
} | |
const Child = () => { | |
const value = useContext(MyContext); | |
return <p>{value}</p> | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment