DEV Community

Discussion on: React Component to draw on a page using Hooks and Typescript

Collapse
 
jibin23 profile image
Jibin Joseph

Please correct the getCoordinates function to return an object with keys x and y, as it is in your codesandbox. In the blogpost it returns an array.

const getCoordinates = (event: MouseEvent): Coordinate | undefined => {
    if (!canvasRef.current) {
        return;
    }

    const canvas: HTMLCanvasElement = canvasRef.current;
    return [event.pageX - canvas.offsetLeft, event.pageY - canvas.offsetTop];
};

Great post!

Collapse
 
ankursheel profile image
Ankur Sheel

Thanks for pointing out the mistake. I have fixed it in the post.
Glad you liked it :)