Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR makes the isLoading prop optional in the AsyncView component and adds automatic loading state inference based on data and error availability.
Key Changes:
- Made
isLoadingprop optional in the component's type definition - Implemented fallback logic to automatically determine loading state when
isLoadingis undefined - Refactored condition checks to use extracted boolean variables for improved readability
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,4 +1,4 @@ | |||
| import React, { ReactElement, ReactNode } from 'react' | |||
| import { ReactElement, ReactNode } from 'react' | |||
There was a problem hiding this comment.
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.
| import { ReactElement, ReactNode } from 'react' | |
| import React, { ReactElement, ReactNode } from 'react' |
There was a problem hiding this comment.
Should be ok, I guess. It was automatically removed.
| const isError = error !== null && error !== undefined | ||
| const hasData = data !== null && data !== undefined | ||
|
|
||
| if (isLoading || (isLoading === undefined && !hasData && !isError)) { |
There was a problem hiding this comment.
The fallback loading state logic !hasData && !isError could incorrectly treat the initial state (no data, no error) as loading even after a request completes with empty/falsy data. Consider whether empty arrays, empty strings, or false as valid data values should trigger loading state.
| 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.
Not true, as we check explicitly for null and undefined.
No description provided.