Skip to content

Instantly share code, notes, and snippets.

@meramos
Created December 20, 2020 04:18
Show Gist options
  • Select an option

  • Save meramos/fba708c587ad9c9fb42fecb232edbcff to your computer and use it in GitHub Desktop.

Select an option

Save meramos/fba708c587ad9c9fb42fecb232edbcff to your computer and use it in GitHub Desktop.
Move dressup state update to its own function.
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