Skip to content

Commit a76a598

Browse files
authored
Fix runtime error in image gallery useState example (#5877)
1 parent d58ca81 commit a76a598

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/content/learn/adding-interactivity.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ import { sculptureList } from './data.js';
9494
export default function Gallery() {
9595
const [index, setIndex] = useState(0);
9696
const [showMore, setShowMore] = useState(false);
97+
const hasNext = index < sculptureList.length - 1;
9798

9899
function handleNextClick() {
99-
setIndex(index + 1);
100+
if (hasNext) {
101+
setIndex(index + 1);
102+
} else {
103+
setIndex(0);
104+
}
100105
}
101106

102107
function handleMoreClick() {

0 commit comments

Comments
 (0)