Created
March 5, 2019 01:00
-
-
Save treyhuffine/9aad7d7d60f72f5c201bc71e148e91bb to your computer and use it in GitHub Desktop.
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 { createContext, useContext } from 'react'; | |
props ITheme { | |
backgroundColor: string; | |
color: string; | |
} | |
// The standard way to create context. It takes an initial value object | |
const ThemeContext = createContext<ITheme>({ | |
backgroundColor: 'black', | |
color: 'white', | |
}) | |
// Accessing context in a child component | |
const themeContext = useContext<ITheme>(ThemeContext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess there's some type error. Probably:
interface ITheme {
backgroundColor: string;
color: string;
}