import * as React from 'react' ; import * as CanvasUtils from '../Utils/CanvasUtils' ; import * as ReactDOM from 'react-dom' ; /**
 * Canvas element that redraws on new props only
 */ class StaticCanvas extends React . Component < any , any > { private canvas : HTMLCanvasElement | any ; public componentDidMount ( ) { this . drawOnce ( ) ; } public componentWillReceiveProps ( ) { this . drawOnce ( ) ; } public render ( ) { return ( < canvas > < /canvas>); } private drawOnce ( ) { const { width , height } = this . props ; const options = this . props . options || { } ; const canvas = this . canvas || ReactDOM . findDOMNode ( this ) ; CanvasUtils . canvasResize ( canvas , width , height ) ; const ctx = canvas . getContext ( '2d' ) ; this . props . draw ( ctx , width , height , options ) ; } } export default StaticCanvas ;