Last active
February 10, 2019 22:57
-
-
Save amanda-mitchell/dbbff27a8b7ac25bf6530a0052ed13db 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
function CanvasComponent() { | |
const canvasRef = useRef<HTMLCanvasElement | null>(null); | |
useBoundEffect(addTouchListener, canvasRef.current); | |
return <canvas ref={canvasRef} />; | |
} | |
function addTouchListener(canvas: HTMLCanvasElement | null) { | |
if (!canvas) { | |
return; | |
} | |
const handleTouchStart = () => { | |
console.log('a touch event started'); | |
}; | |
canvas.addEventListener('touchstart', handleTouchStart); | |
return () => canvas.removeEventListener('touchstart', handleTouchStart); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment