Created
May 6, 2025 12:59
-
-
Save Baldrani/d1c3f58182726877e060a9417b519885 to your computer and use it in GitHub Desktop.
Loop on array without loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const changeMessage = React.useCallback(() => { | |
| const currentIndex = shuffledMessages.indexOf(message); | |
| const nextIndex = (currentIndex + 1) % shuffledMessages.length; | |
| setMessage(shuffledMessages[nextIndex]); | |
| }, [message, shuffledMessages]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment