Skip to content

Instantly share code, notes, and snippets.

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