@@ -247,13 +247,13 @@ export default function CatFriends() {
247
247
< nav>
248
248
< button onClick= {() => scrollToCat (catList[0 ])}> Neo< / button>
249
249
< button onClick= {() => scrollToCat (catList[5 ])}> Millie< / button>
250
- < button onClick= {() => scrollToCat (catList[9 ])}> Bella< / button>
250
+ < button onClick= {() => scrollToCat (catList[8 ])}> Bella< / button>
251
251
< / nav>
252
252
< div>
253
253
< ul>
254
254
{catList .map ((cat ) => (
255
255
< li
256
- key= {cat}
256
+ key= {cat . id }
257
257
ref= {(node ) => {
258
258
const map = getMap ();
259
259
map .set (cat, node);
@@ -263,7 +263,7 @@ export default function CatFriends() {
263
263
};
264
264
}}
265
265
>
266
- < img src= {cat} / >
266
+ < img src= {cat . imageUrl } / >
267
267
< / li>
268
268
))}
269
269
< / ul>
@@ -273,11 +273,22 @@ export default function CatFriends() {
273
273
}
274
274
275
275
function setupCatList () {
276
- const catList = [];
277
- for (let i = 0 ; i < 10 ; i++ ) {
278
- catList .push (" https://loremflickr.com/320/240/cat?lock=" + i);
276
+ const catCount = 10 ;
277
+ const catList = new Array (catCount)
278
+ for (let i = 0 ; i < catCount; i++ ) {
279
+ let imageUrl = ' ' ;
280
+ if (i < 5 ) {
281
+ imageUrl = " https://placecats.com/neo/320/240" ;
282
+ } else if (i < 8 ) {
283
+ imageUrl = " https://placecats.com/millie/320/240" ;
284
+ } else {
285
+ imageUrl = " https://placecats.com/bella/320/240" ;
286
+ }
287
+ catList[i] = {
288
+ id: i,
289
+ imageUrl,
290
+ };
279
291
}
280
-
281
292
return catList;
282
293
}
283
294
@@ -876,12 +887,30 @@ export default function CatFriends() {
876
887
);
877
888
}
878
889
879
- const catList = [];
880
- for (let i = 0 ; i < 10 ; i++ ) {
881
- catList .push ({
890
+ const catCount = 10 ;
891
+ const catList = new Array (catCount);
892
+ for (let i = 0 ; i < catCount; i++ ) {
893
+ const bucket = Math .floor (Math .random () * catCount) % 2 ;
894
+ let imageUrl = ' ' ;
895
+ switch (bucket) {
896
+ case 0 : {
897
+ imageUrl = " https://placecats.com/neo/250/200" ;
898
+ break ;
899
+ }
900
+ case 1 : {
901
+ imageUrl = " https://placecats.com/millie/250/200" ;
902
+ break ;
903
+ }
904
+ case 2 :
905
+ default : {
906
+ imageUrl = " https://placecats.com/bella/250/200" ;
907
+ break ;
908
+ }
909
+ }
910
+ catList[i] = {
882
911
id: i,
883
- imageUrl: ' https://loremflickr.com/250/200/cat?lock= ' + i
884
- }) ;
912
+ imageUrl,
913
+ };
885
914
}
886
915
887
916
```
@@ -961,7 +990,7 @@ export default function CatFriends() {
961
990
behavior: ' smooth' ,
962
991
block: ' nearest' ,
963
992
inline: ' center'
964
- });
993
+ });
965
994
}}>
966
995
Next
967
996
< / button>
@@ -993,12 +1022,30 @@ export default function CatFriends() {
993
1022
);
994
1023
}
995
1024
996
- const catList = [];
997
- for (let i = 0 ; i < 10 ; i++ ) {
998
- catList .push ({
1025
+ const catCount = 10 ;
1026
+ const catList = new Array (catCount);
1027
+ for (let i = 0 ; i < catCount; i++ ) {
1028
+ const bucket = Math .floor (Math .random () * catCount) % 2 ;
1029
+ let imageUrl = ' ' ;
1030
+ switch (bucket) {
1031
+ case 0 : {
1032
+ imageUrl = " https://placecats.com/neo/250/200" ;
1033
+ break ;
1034
+ }
1035
+ case 1 : {
1036
+ imageUrl = " https://placecats.com/millie/250/200" ;
1037
+ break ;
1038
+ }
1039
+ case 2 :
1040
+ default : {
1041
+ imageUrl = " https://placecats.com/bella/250/200" ;
1042
+ break ;
1043
+ }
1044
+ }
1045
+ catList[i] = {
999
1046
id: i,
1000
- imageUrl: ' https://loremflickr.com/250/200/cat?lock= ' + i
1001
- }) ;
1047
+ imageUrl,
1048
+ };
1002
1049
}
1003
1050
1004
1051
```
0 commit comments