Skip to content

Instantly share code, notes, and snippets.

@colinfwren
Created September 1, 2019 13:36
Show Gist options
  • Save colinfwren/84917dee10e4e532065a443455b7b678 to your computer and use it in GitHub Desktop.
Save colinfwren/84917dee10e4e532065a443455b7b678 to your computer and use it in GitHub Desktop.
Theme Context Provider and withTheme HOC
import React, { useContext } from 'react';
const ThemeContext = React.createContext();
export const ThemeContextProvider = ({ children, theme }) => (
<ThemeContext.Provider value={{ theme }}>
{children}
</ThemeContext.Provider>
);
export function withTheme(Component) {
return (props) => {
const { theme } = useContext(ThemeContext);
return <Component {...props} theme={theme} />;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment