File tree Expand file tree Collapse file tree 3 files changed +7
-13
lines changed Expand file tree Collapse file tree 3 files changed +7
-13
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,12 @@ const SnippetList = () => {
36
36
< >
37
37
< motion . ul role = "list" className = "snippets" >
38
38
< AnimatePresence mode = "popLayout" >
39
- { fetchedSnippets . map ( ( currentSnippet , idx ) => {
39
+ { fetchedSnippets . map ( ( snippet , idx ) => {
40
+ const uniqueId = `${ snippet . title } -${ snippet . description } ` ;
40
41
return (
41
42
< motion . li
42
- key = { currentSnippet . title + idx }
43
- layoutId = { currentSnippet . title + ( idx + 1 ) . toString ( ) } // unique id for layout animation
43
+ key = { uniqueId }
44
+ layoutId = { uniqueId }
44
45
initial = { { opacity : 0 , y : 20 } }
45
46
animate = { {
46
47
opacity : 1 ,
@@ -66,20 +67,14 @@ const SnippetList = () => {
66
67
< motion . button
67
68
className = "snippet | flow"
68
69
data-flow-space = "sm"
69
- onClick = { ( ) =>
70
- handleOpenModal ( {
71
- ...currentSnippet ,
72
- // added idx for the layout animation to work correctly
73
- idx : idx + 1 ,
74
- } )
75
- }
70
+ onClick = { ( ) => handleOpenModal ( snippet ) }
76
71
whileHover = { { scale : 1.01 } }
77
72
whileTap = { { scale : 0.98 } }
78
73
>
79
74
< div className = "snippet__preview" >
80
75
< img src = { language . icon } alt = { language . lang } />
81
76
</ div >
82
- < h3 className = "snippet__title" > { currentSnippet . title } </ h3 >
77
+ < h3 className = "snippet__title" > { snippet . title } </ h3 >
83
78
</ motion . button >
84
79
</ motion . li >
85
80
) ;
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ const SnippetModal: React.FC<Props> = ({
49
49
key = "modal-content"
50
50
className = "modal | flow"
51
51
data-flow-space = "lg"
52
- layoutId = { snippet . title + snippet . idx ?. toString ( ) } // unique id for layout animation
52
+ layoutId = { ` ${ snippet . title } - ${ snippet . description } ` }
53
53
transition = { { type : "spring" , duration : shouldReduceMotion ? 0 : 0.5 } }
54
54
>
55
55
< div className = "modal__header" >
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ export type SnippetType = {
14
14
code : string ;
15
15
tags : string [ ] ;
16
16
author : string ;
17
- idx ?: number ;
18
17
} ;
19
18
20
19
export type AppState = {
You can’t perform that action at this time.
0 commit comments