From 6edd2c954e5be0c645fb31705a8b193ae2868b27 Mon Sep 17 00:00:00 2001 From: Green apple <0xgreenapple@gmail.com> Date: Fri, 5 Apr 2024 19:40:12 +0530 Subject: [PATCH 1/2] fix random function imports and the type --- src/index.tsx | 2 +- src/lib/iconBase.tsx | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index d8c161d..53c1345 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,2 +1,2 @@ export * from "./lib/shapes"; -export { default as shapes, shapeTypes } from "./shapes"; +export { default as shapes, shapeTypes, getRandomShape } from "./shapes"; diff --git a/src/lib/iconBase.tsx b/src/lib/iconBase.tsx index 5002b48..7446d3c 100644 --- a/src/lib/iconBase.tsx +++ b/src/lib/iconBase.tsx @@ -7,9 +7,8 @@ import React, { import NoiseMask from "./noiseMask"; // icon base props -export interface ShapeProps - extends RefAttributes, - Partial> { +type svgProps = RefAttributes & Partial>; +export interface ShapeProps extends svgProps{ size?: number; noise?: boolean; } From eaf0d21e45b5949e7510e777ca6d8830af0e522a Mon Sep 17 00:00:00 2001 From: Green apple <0xgreenapple@gmail.com> Date: Sun, 7 Apr 2024 20:45:44 +0530 Subject: [PATCH 2/2] fix state issue in coolshape component --- src/lib/shapes.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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";