Skip to content

Commit 85ee6b2

Browse files
authored
Remove deprecated loremflickr placeholder images (#7968)
The previous examples used a service called loremflickr.com to link to placeholder images. Since that service is now down, I updated them to reference placecats.com instead, which we already use in other examples as well. placecats doesn't have the same random cat feature so I roughly approximated it in the example code. Closes #7966
1 parent ff11cd2 commit 85ee6b2

File tree

2 files changed

+173
-129
lines changed

2 files changed

+173
-129
lines changed

src/content/learn/manipulating-the-dom-with-refs.md

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ export default function CatFriends() {
247247
<nav>
248248
<button onClick={() => scrollToCat(catList[0])}>Neo</button>
249249
<button onClick={() => scrollToCat(catList[5])}>Millie</button>
250-
<button onClick={() => scrollToCat(catList[9])}>Bella</button>
250+
<button onClick={() => scrollToCat(catList[8])}>Bella</button>
251251
</nav>
252252
<div>
253253
<ul>
254254
{catList.map((cat) => (
255255
<li
256-
key={cat}
256+
key={cat.id}
257257
ref={(node) => {
258258
const map = getMap();
259259
map.set(cat, node);
@@ -263,7 +263,7 @@ export default function CatFriends() {
263263
};
264264
}}
265265
>
266-
<img src={cat} />
266+
<img src={cat.imageUrl} />
267267
</li>
268268
))}
269269
</ul>
@@ -273,11 +273,22 @@ export default function CatFriends() {
273273
}
274274

275275
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+
};
279291
}
280-
281292
return catList;
282293
}
283294

@@ -876,12 +887,30 @@ export default function CatFriends() {
876887
);
877888
}
878889

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] = {
882911
id: i,
883-
imageUrl: 'https://loremflickr.com/250/200/cat?lock=' + i
884-
});
912+
imageUrl,
913+
};
885914
}
886915

887916
```
@@ -961,7 +990,7 @@ export default function CatFriends() {
961990
behavior: 'smooth',
962991
block: 'nearest',
963992
inline: 'center'
964-
});
993+
});
965994
}}>
966995
Next
967996
</button>
@@ -993,12 +1022,30 @@ export default function CatFriends() {
9931022
);
9941023
}
9951024

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] = {
9991046
id: i,
1000-
imageUrl: 'https://loremflickr.com/250/200/cat?lock=' + i
1001-
});
1047+
imageUrl,
1048+
};
10021049
}
10031050

10041051
```

0 commit comments

Comments
 (0)