Skip to content

Instantly share code, notes, and snippets.

@siman
Created June 3, 2021 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siman/c4ef6b5fca02846897a3a9ddc4bc3793 to your computer and use it in GitHub Desktop.
Save siman/c4ef6b5fca02846897a3a9ddc4bc3793 to your computer and use it in GitHub Desktop.
export type AsyncHookResult<R = void> = {
loading?: boolean
error?: Error
result?: R // TODO require R if loading is true
}
export function newAsyncHookLoading<R = void> (loading = true): AsyncHookResult<R> {
return { loading }
}
export function newAsyncHookResult<R = void> (result: R): AsyncHookResult<R> {
return { loading: false, result }
}
export function newAsyncHookError<R = void> (error: Error): AsyncHookResult<R> {
return { loading: false, error }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment