Skip to content

Commit

Permalink
fix(popper): adding missing memoisation
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoguzmana committed Dec 10, 2022
1 parent 9dc7d6c commit ea500e9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,18 @@ export const Popper = memo(
[direction]
);

const optimalNumberOfItems = Math.floor(screenWidth / spacing);
const itemsToRenderArray = [...Array(optimalNumberOfItems)];
const optimalNumberOfItems = useMemo(
() => Math.floor(screenWidth / spacing),
[spacing]
);
const itemsToRenderArray = useMemo(
() => [...Array(optimalNumberOfItems)],
[optimalNumberOfItems]
);

const yPositions = shuffleArray(
itemsToRenderArray.map((_, i) => i * spacing)
const yPositions = useMemo(
() => shuffleArray(itemsToRenderArray.map((_, i) => i * spacing)),
[itemsToRenderArray, spacing]
);

const containerYPosition = useValue(initialPosition);
Expand Down

0 comments on commit ea500e9

Please sign in to comment.