Skip to content

Instantly share code, notes, and snippets.

@karooolis
Created July 25, 2018 05:24
Show Gist options
  • Save karooolis/b4647841c99ee99120fb533bfb050abe to your computer and use it in GitHub Desktop.
Save karooolis/b4647841c99ee99120fb533bfb050abe to your computer and use it in GitHub Desktop.
import React from 'react';
const withColor = BaseComponent => {
class EnhancedComponent extends React.Component {
getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
render() {
return <BaseComponent color={this.getRandomColor()} {...this.props} />;
}
}
return EnhancedComponent;
};
export default withColor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment