Skip to content

Instantly share code, notes, and snippets.

@JakeCoxon
Created January 1, 2017 15:02
Show Gist options
  • Save JakeCoxon/7afcca88f9a4888b79c76856e0544aaf to your computer and use it in GitHub Desktop.
Save JakeCoxon/7afcca88f9a4888b79c76856e0544aaf to your computer and use it in GitHub Desktop.
class Canvas extends React.Component {
componentDidMount() {
this.props.draw(this.refs.a.getContext('2d'));
}
render() {
const { width, height } = this.props;
return <canvas ref='a'
width={width}
height={height}
style={{width, height}}/>
}
};
const draw = color => ctx => {
ctx.fillStyle = 'black';
ctx.fillRect(25,5, 40, 40);
ctx.fillStyle = color;
ctx.fillRect(20,0 , 40, 40);
};
<Canvas width={200} height={100} draw={draw('red')} />;
<Canvas width={200} height={100} draw={draw('#ffaa00')} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment