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}