-
Notifications
You must be signed in to change notification settings - Fork 0
add fallback behaviour for is-loading #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||
| import React, { ReactElement, ReactNode } from 'react' | ||||||||
| import { ReactElement, ReactNode } from 'react' | ||||||||
| import { isFunction } from '../util' | ||||||||
|
|
||||||||
| type LoadingFunction = () => ReactNode | ||||||||
|
|
@@ -8,7 +8,7 @@ type ErrorFunction<Error> = (error: NonNullable<Error>) => ReactNode | |||||||
| type Props<Data, Error> = { | ||||||||
| data?: Data | ||||||||
| error?: Error | ||||||||
| isLoading: boolean | ||||||||
| isLoading?: boolean | ||||||||
| renderLoading?: ReactNode | LoadingFunction | ||||||||
| renderError?: ReactNode | ErrorFunction<Error> | ||||||||
| } & ( | ||||||||
|
|
@@ -36,15 +36,18 @@ const AsyncView = <Data, Error>( | |||||||
| allowMissingData = false, | ||||||||
| } = props | ||||||||
|
|
||||||||
| if (isLoading) { | ||||||||
| const isError = error !== null && error !== undefined | ||||||||
| const hasData = data !== null && data !== undefined | ||||||||
|
|
||||||||
| if (isLoading || (isLoading === undefined && !hasData && !isError)) { | ||||||||
|
||||||||
| if (isLoading || (isLoading === undefined && !hasData && !isError)) { | |
| // Show loading only if isLoading is true, or if isLoading is undefined and both data and error are undefined/null (initial state) | |
| if (isLoading === true || (isLoading === undefined && !hasData && !isError)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not true, as we check explicitly for null and undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The React import was removed but ReactElement and ReactNode types are still being imported. Since this component returns JSX (line 43, 47), React needs to be in scope for older React versions or the JSX transform configuration should be verified to ensure the automatic JSX runtime is enabled.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ok, I guess. It was automatically removed.