Created
January 1, 2017 15:02
-
-
Save JakeCoxon/7afcca88f9a4888b79c76856e0544aaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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