2019-12-04 16:39:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
export const ThemeContext = React.createContext({ theme: 'light' });
|
2019-12-04 16:39:53 +00:00
|
|
|
|
|
|
|
export function withTheme(Component) {
|
|
|
|
const ThemedComponent = props => (
|
|
|
|
<ThemeContext.Consumer>
|
|
|
|
{contexts => <Component {...props} {...contexts} />}
|
|
|
|
</ThemeContext.Consumer>
|
|
|
|
);
|
|
|
|
hoistNonReactStatics(ThemedComponent, Component);
|
|
|
|
return ThemedComponent;
|
|
|
|
}
|