File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -20,21 +20,20 @@ const Coolshape: ForwardRefExoticComponent<ShapeOptions> = forwardRef(
20
20
( options , ref ) => {
21
21
const { type, index, random, ...rest } = options ;
22
22
23
- let initialShape = null ;
24
- if ( index !== undefined && type ) {
25
- initialShape = shapes [ type ] [ index ] ;
23
+ if ( index !== undefined && type && ! random ) {
24
+ const Shape = shapes [ type ] [ index ] ;
25
+ return < Shape { ... rest } ref = { ref } />
26
26
}
27
- const [ Shape , setShape ] = useState < ShapeType | null > ( initialShape ) ;
27
+
28
+ const [ RandomShape , setRandomShape ] = useState < ShapeType | null > ( null ) ;
28
29
useEffect ( ( ) => {
29
- if ( random || ! type || index === undefined ) {
30
30
const shape = getRandomShape ( { type } ) as ShapeType ;
31
- setShape ( shape ) ;
32
- }
31
+ setRandomShape ( shape ) ;
33
32
} , [ ] ) ;
34
- if ( ! Shape ) {
35
- return null ;
33
+ if ( ! RandomShape ) {
34
+ return null ;
36
35
}
37
- return < Shape { ...rest } ref = { ref } /> ;
36
+ return < RandomShape { ...rest } ref = { ref } /> ;
38
37
}
39
38
) ;
40
39
Coolshape . displayName = "Coolshape" ;
You can’t perform that action at this time.
0 commit comments