From eb63f0b3fdca7ea3c2c8c2451b3718febba55763 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 18 Dec 2022 17:56:38 -0600 Subject: [PATCH] Adjust loopback arrow, memoized responsive loop state, center boxes - Boxes weren't centered, this was more noticeable for smaller loop sizes --- src/components/BoxLoop.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/BoxLoop.tsx b/src/components/BoxLoop.tsx index 82c50e0..ef7bc10 100644 --- a/src/components/BoxLoop.tsx +++ b/src/components/BoxLoop.tsx @@ -1,4 +1,4 @@ -import React, {FunctionComponent, useState} from "react"; +import React, {FunctionComponent, useMemo} from "react"; import Chance from "chance"; import {getColor, range} from "@/utils/helpers"; import BoxGraphic from "@/components/BoxGraphic"; @@ -35,18 +35,20 @@ function createLoop(loopRange: [number, number], count: number): { start: number } const BoxLoop: FunctionComponent = ({count}: BoxLoopProps) => { - const [{loop, start, list}] = useState(createLoop([1, 100], count)!); + const {loop, list} = useMemo(() => { + return createLoop([1, 100], count)!; + }, [count]) - return
{list.map((v, index) => { const [sourceKey, destinationKey] = [`x-${v}`, `x-${loop[v]}`]; const isLast = index == count - 1; return ( -
+
+ className="box flex flex-col items-center justify-center aspect-square relative">
{loop[v]}
= ({count}: BoxLoopProps) => { {v} {loop[v] ? - : null}