Skip to content

Instantly share code, notes, and snippets.

@michal-wrzosek
Last active February 26, 2019 07:47
Show Gist options
  • Save michal-wrzosek/0a1d864805b5c13bbdc6a9a5ee14a641 to your computer and use it in GitHub Desktop.
Save michal-wrzosek/0a1d864805b5c13bbdc6a9a5ee14a641 to your computer and use it in GitHub Desktop.
const theme = {
fontColor: 'red',
};
// HOC
const withTheme = (Component) => props => <Component {...props} theme={theme} />;
// Component
const List = ({ items, theme }) => (
<ul style={{ color: theme.fontColor }}>
{items.map((item, index) => (
<li key={index}>{item}</li>
))}
</ul>
);
// Wrapping Component in HOC
const ListWithTheme = withTheme(List);
const App = () => <ListWithTheme items={['one', 'two', 'three']} />;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment