Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import React, { useContext } from 'react';
  2. import { usePersistState } from 'hooks/usePersistState';
  3.  
  4. const Context = React.createContext('default');
  5.  
  6. const Theme = ({ theme, children }) => {
  7. const [_theme, setTheme] = usePersistState({ key: 'theme', defaultValue: theme });
  8.  
  9. return (
  10. <Context.Provider value={{ theme: _theme, setTheme }}>
  11. {children}
  12. </Context.Provider>
  13. )
  14. };
  15.  
  16. export const withTheme = (Component) =>
  17. (props) => (<Component {...props} {...useContext(Context)} />);
  18.  
  19. export default Theme;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement