Skip to content

Instantly share code, notes, and snippets.

@zackshapiro
Created June 14, 2019 23:16
Show Gist options
  • Save zackshapiro/65fac6ee5056fb0912220022003aa2c8 to your computer and use it in GitHub Desktop.
Save zackshapiro/65fac6ee5056fb0912220022003aa2c8 to your computer and use it in GitHub Desktop.
const countRef = useRef(0)
// Processes the next pending thumbnail when ready
useEffect(() => {
if (state.pending.length && state.next) {
const { next } = state
api
.uploadFile(next)
.then(() => {
const prev = next
logUploadedFile(++countRef.current)
const pending = state.pending.slice(1)
dispatch({ type: 'file-uploaded', prev, pending })
})
.catch((error) => {
console.error(error)
dispatch({ type: 'set-upload-error', error })
})
}
}, [state])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment