Skip to content

Instantly share code, notes, and snippets.

@treyhuffine
Created March 5, 2019 01:00
Show Gist options
  • Save treyhuffine/9aad7d7d60f72f5c201bc71e148e91bb to your computer and use it in GitHub Desktop.
Save treyhuffine/9aad7d7d60f72f5c201bc71e148e91bb to your computer and use it in GitHub Desktop.
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);
@ayushbpl10
Copy link

I guess there's some type error. Probably:
interface ITheme {
backgroundColor: string;
color: string;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment