feat: memoize highlighter rect calc
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { coordinateMapper } from '../../helpers/coordinateMapper';
|
import { coordinateMapper } from '../../helpers/coordinateMapper';
|
||||||
|
|
||||||
@@ -14,16 +14,15 @@ const HighlighterComponent = ({ unmodifiedRect, displayedSelector = '', width, h
|
|||||||
if (!unmodifiedRect) {
|
if (!unmodifiedRect) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
const mappedRect = coordinateMapper.mapBrowserRectToCanvas(unmodifiedRect);
|
const rect = useMemo(() => {
|
||||||
|
const mappedRect = coordinateMapper.mapBrowserRectToCanvas(unmodifiedRect);
|
||||||
const rect = {
|
return {
|
||||||
top: mappedRect.top + canvasRect.top + window.scrollY,
|
top: mappedRect.top + canvasRect.top + window.scrollY,
|
||||||
left: mappedRect.left + canvasRect.left + window.scrollX,
|
left: mappedRect.left + canvasRect.left + window.scrollX,
|
||||||
right: mappedRect.right + canvasRect.left,
|
width: mappedRect.width,
|
||||||
bottom: mappedRect.bottom + canvasRect.top,
|
height: mappedRect.height,
|
||||||
width: mappedRect.width,
|
};
|
||||||
height: mappedRect.height,
|
}, [unmodifiedRect, canvasRect.top, canvasRect.left]);
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user