Created
March 23, 2021 06:54
-
-
Save night-fury-rider/687cdbacf2fd7f524f7e6af5543ba531 to your computer and use it in GitHub Desktop.
React - Context API
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 from 'react'; | |
const UserContext = React.createContext('Yuvraj'); | |
const UserProvider = UserContext.Provider; | |
const UserConsumer = UserContext.Consumer; | |
function UVHeader() { | |
return ( | |
<UserConsumer> | |
{ | |
(contextData) => { | |
return contextData; | |
} | |
} | |
</UserConsumer> | |
) | |
} | |
function App() { | |
return ( | |
<UserProvider value="Yuvi"> | |
<UVHeader /> | |
</UserProvider> | |
) | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment