Skip to content

Instantly share code, notes, and snippets.

@leonardfactory
Last active February 20, 2019 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardfactory/c722ad7a389cc7ced9d74f7c9c488525 to your computer and use it in GitHub Desktop.
Save leonardfactory/c722ad7a389cc7ced9d74f7c9c488525 to your computer and use it in GitHub Desktop.
React Apollo & Hooks
// Let's define our context...
const ThemeContext = React.createContext(...);
// This component is nested in a `ThemeContext.Provider` node..
function MyComponent(props: Props) {
// No more HOCs!
const theme = useContext(ThemeContext);
// It's a kind of magic
return (
<h1 style={{ color: theme.color }}>{props.title}</h1>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment