Skip to content

Instantly share code, notes, and snippets.

@karooolis
Created July 25, 2018 10:35
Show Gist options
  • Save karooolis/16dd46a515d0b20bfaf41eb5797b8b4b to your computer and use it in GitHub Desktop.
Save karooolis/16dd46a515d0b20bfaf41eb5797b8b4b to your computer and use it in GitHub Desktop.
import React from 'react';
const withColor = BaseComponent => {
console.log(this);
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() {
console.log(this);
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