Skip to content

Instantly share code, notes, and snippets.

@night-fury-rider
Created March 23, 2021 06:54
Show Gist options
  • Save night-fury-rider/687cdbacf2fd7f524f7e6af5543ba531 to your computer and use it in GitHub Desktop.
Save night-fury-rider/687cdbacf2fd7f524f7e6af5543ba531 to your computer and use it in GitHub Desktop.
React - Context API
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