Skip to content

Instantly share code, notes, and snippets.

@solomon-gumball
Last active August 6, 2020 22:06
Show Gist options
  • Save solomon-gumball/c32303a61b6d7180d1eea13ab5ffa691 to your computer and use it in GitHub Desktop.
Save solomon-gumball/c32303a61b6d7180d1eea13ab5ffa691 to your computer and use it in GitHub Desktop.
type AsyncDispatch<T> = Dispatch<T | Promise<T>>
function wrapAsync<T>(dispatch: Dispatch<T>): AsyncDispatch<T> {
return (action: T | Promise<T>) => {
if (action instanceof Promise) {
return action.then(dispatch)
}
return dispatch(action)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment