Created
March 7, 2021 18:19
-
-
Save piotrrussw/c041efa7bde31eb7c1567595d7e93892 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
const onMove = useCallback( | |
(event) => { | |
if (drawing) { | |
const newPosition = getCoordinates(event) | |
if (position && newPosition) { | |
drawLine(position, newPosition) | |
setPosition(newPosition) | |
} | |
} | |
}, | |
[drawing, position] | |
) | |
const drawLine = (originalPosition, newPosition) => { | |
if (!canvas.current) { | |
return null | |
} | |
const context = canvas.current.getContext('2d') | |
if (context) { | |
context.strokeStyle = '#7030A2' | |
context.lineJoin = 'round' | |
context.lineWidth = 5 | |
context.beginPath() | |
context.moveTo(originalPosition.x, originalPosition.y) | |
context.lineTo(newPosition.x, newPosition.y) | |
context.closePath() | |
context.stroke() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment