Last active
August 6, 2020 22:06
-
-
Save solomon-gumball/c32303a61b6d7180d1eea13ab5ffa691 to your computer and use it in GitHub Desktop.
This file contains 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
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