Created
June 3, 2021 15:19
-
-
Save siman/c4ef6b5fca02846897a3a9ddc4bc3793 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
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