Skip to content

Commit

Permalink
chore: add useCallback for getPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan committed Dec 17, 2020
1 parent 1bccb90 commit 757f610
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/drawing/DrawingCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function DrawingCreator({ className, onStart, onStop, stroke = de
const drawingSVGRef = React.useRef<DrawingSVGRef>(null);
const renderHandleRef = React.useRef<number | null>(null);

const getPoints = (): Array<Position> => {
const getPoints = React.useCallback((): Array<Position> => {
const { current: creatorEl } = creatorElRef;
const { current: points } = capturedPointsRef;

Expand All @@ -47,7 +47,8 @@ export default function DrawingCreator({ className, onStart, onStop, stroke = de
x: (Math.min(MAX_X, Math.max(minSize, x)) / width) * 100,
y: (Math.min(MAX_Y, Math.max(minSize, y)) / height) * 100,
}));
};
}, [stroke]);

const getPosition = (x: number, y: number): [number, number] => {
const { current: creatorEl } = creatorElRef;

Expand Down Expand Up @@ -88,7 +89,7 @@ export default function DrawingCreator({ className, onStart, onStop, stroke = de
paths: [{ points: adjustedPoints }],
stroke,
});
}, [onStop, setDrawingStatus, stroke]);
}, [getPoints, onStop, setDrawingStatus, stroke]);

const updateDraw = React.useCallback(
(x: number, y: number): void => {
Expand Down

0 comments on commit 757f610

Please sign in to comment.