Created
September 1, 2019 13:36
-
-
Save colinfwren/84917dee10e4e532065a443455b7b678 to your computer and use it in GitHub Desktop.
Theme Context Provider and withTheme HOC
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 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