Skip to content

Instantly share code, notes, and snippets.

@amanda-mitchell
Last active February 10, 2019 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amanda-mitchell/dbbff27a8b7ac25bf6530a0052ed13db to your computer and use it in GitHub Desktop.
Save amanda-mitchell/dbbff27a8b7ac25bf6530a0052ed13db to your computer and use it in GitHub Desktop.
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