diff --git a/src/lib/shapes.tsx b/src/lib/shapes.tsx index d6498df..6adcc5d 100644 --- a/src/lib/shapes.tsx +++ b/src/lib/shapes.tsx @@ -20,21 +20,20 @@ const Coolshape: ForwardRefExoticComponent = forwardRef( (options, ref) => { const { type, index, random, ...rest } = options; - let initialShape = null; - if (index !== undefined && type) { - initialShape = shapes[type][index]; + if (index !== undefined && type && !random) { + const Shape = shapes[type][index]; + return } - const [Shape, setShape] = useState(initialShape); + + const [RandomShape, setRandomShape] = useState(null); useEffect(() => { - if (random || !type || index === undefined) { const shape = getRandomShape({ type }) as ShapeType; - setShape(shape); - } + setRandomShape(shape); }, []); - if (!Shape) { - return null; + if (!RandomShape) { + return null; } - return ; + return ; } ); Coolshape.displayName = "Coolshape";