Created
July 4, 2019 17:10
-
-
Save icarus-sullivan/50b163ae8e239c0d00a5807a626fdca8 to your computer and use it in GitHub Desktop.
Show the simplicity needed for a contextual 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'; | |
import { usePersistState } from 'hooks/usePersistState'; | |
const Context = React.createContext('default'); | |
const Theme = ({ theme, children }) => { | |
const [_theme, setTheme] = usePersistState({ key: 'theme', defaultValue: theme }); | |
return ( | |
<Context.Provider value={{ theme: _theme, setTheme }}> | |
{children} | |
</Context.Provider> | |
) | |
}; | |
export const withTheme = (Component) => | |
(props) => (<Component {...props} {...useContext(Context)} />); | |
export default Theme; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment