Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Last active July 23, 2019 20:07
Show Gist options
  • Save jrwebdev/68e50bcd9ef2a125933355369c155047 to your computer and use it in GitHub Desktop.
Save jrwebdev/68e50bcd9ef2a125933355369c155047 to your computer and use it in GitHub Desktop.
type Theme = 'light' | 'dark';
const ThemeContext = createContext<Theme>('dark');
const App = () => (
<ThemeContext.Provider value="dark">
<MyComponent />
</ThemeContext.Provider>
)
const MyComponent = () => {
const theme = useContext(ThemeContext);
return <div>The theme is {theme}</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment