File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 1- import React , { ReactElement , ReactNode } from 'react'
1+ import { ReactElement , ReactNode } from 'react'
22import { isFunction } from '../util'
33
44type LoadingFunction = ( ) => ReactNode
@@ -8,7 +8,7 @@ type ErrorFunction<Error> = (error: NonNullable<Error>) => ReactNode
88type Props < Data , Error > = {
99 data ?: Data
1010 error ?: Error
11- isLoading : boolean
11+ isLoading ? : boolean
1212 renderLoading ?: ReactNode | LoadingFunction
1313 renderError ?: ReactNode | ErrorFunction < Error >
1414} & (
@@ -36,15 +36,18 @@ const AsyncView = <Data, Error>(
3636 allowMissingData = false ,
3737 } = props
3838
39- if ( isLoading ) {
39+ const isError = error !== null && error !== undefined
40+ const hasData = data !== null && data !== undefined
41+
42+ if ( isLoading || ( isLoading === undefined && ! hasData && ! isError ) ) {
4043 return < > { isFunction ( renderLoading ) ? renderLoading ( ) : renderLoading } </ >
4144 }
4245
43- if ( error !== null && error !== undefined ) {
46+ if ( isError ) {
4447 return < > { isFunction ( renderError ) ? renderError ( error ) : renderError } </ >
4548 }
4649
47- if ( ( data === undefined || data === null ) && ! allowMissingData ) {
50+ if ( ! hasData && ! allowMissingData ) {
4851 throw new Error (
4952 'Data passed into AsyncView was null or undefined. Use allowMissingData=true if this is intended.' ,
5053 )
You can’t perform that action at this time.
0 commit comments