Created
December 20, 2020 04:18
-
-
Save meramos/fba708c587ad9c9fb42fecb232edbcff to your computer and use it in GitHub Desktop.
Move dressup state update to its own function.
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
| function next(item){ | |
| let next_num = dressupState[item].current + 1 | |
| // if next_num exceeds total, restart (set current to 0) | |
| let new_current = next_num < dressupState[item].total ? next_num : 0 | |
| updateDressUp(item, new_current) | |
| } | |
| function updateDressUp(item,new_current){ | |
| setDressupState({ | |
| ...dressupState, | |
| [item]: { | |
| current: dressupState[item].current = new_current, | |
| total: dressupState[item].total | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment