@protonapp/react-native-material-ui
Version:
React Native Material Design Components
24 lines (19 loc) • 607 B
JavaScript
import React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import ThemeContext from './themeContext';
// This function takes a component...
const withTheme = WrappedComponent => {
// ...and returns another component...
class ThemedComponent extends React.PureComponent {
render() {
return (
<ThemeContext.Consumer>
{theme => <WrappedComponent {...this.props} theme={theme} />}
</ThemeContext.Consumer>
);
}
}
hoistNonReactStatics(ThemedComponent, WrappedComponent);
return ThemedComponent;
};
export default withTheme;