You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The `[` and `]` syntax here is called [array destructuring](https://javascript.info/destructuring-assignment) and it lets you read values from an array. The array returned by `useState` always has exactly two items.
192
192
193
-
This is how they work together in `handleClick`:
193
+
This is how they work together in `handleClick` (`% sculptureList.length` is used to return to the first item when the index exceeds the list index):
194
194
195
195
```js
196
196
functionhandleClick() {
197
-
setIndex(index +1);
197
+
setIndex((index +1) %sculptureList.length);
198
198
}
199
199
```
200
200
@@ -210,7 +210,7 @@ export default function Gallery() {
210
210
const [index, setIndex] =useState(0);
211
211
212
212
functionhandleClick() {
213
-
setIndex(index +1);
213
+
setIndex((index +1) %sculptureList.length);
214
214
}
215
215
216
216
let sculpture = sculptureList[index];
@@ -394,7 +394,7 @@ export default function Gallery() {
394
394
const [showMore, setShowMore] =useState(false);
395
395
396
396
functionhandleNextClick() {
397
-
setIndex(index +1);
397
+
setIndex((index +1) %sculptureList.length);
398
398
}
399
399
400
400
functionhandleMoreClick() {
@@ -759,7 +759,7 @@ export default function Gallery() {
759
759
const [showMore, setShowMore] =useState(false);
760
760
761
761
functionhandleNextClick() {
762
-
setIndex(index +1);
762
+
setIndex((index +1) %sculptureList.length);
763
763
}
764
764
765
765
functionhandleMoreClick() {
@@ -930,7 +930,7 @@ export default function Gallery() {
930
930
const [showMore, setShowMore] =useState(false);
931
931
932
932
functionhandleNextClick() {
933
-
setIndex(index +1);
933
+
setIndex((index +1) %sculptureList.length);
934
934
}
935
935
936
936
functionhandleMoreClick() {
@@ -1082,7 +1082,7 @@ export default function Gallery() {
0 commit comments