Skip to content

fix: isLoading check for array responses #200

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

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/hooks/internal/_useResolveAsyncCall/_useResolveAsyncCall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isDeepEqual from "fast-deep-equal/react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useMoralis } from "../../../hooks/core/useMoralis";
import { useImmer } from "use-immer";

Expand Down Expand Up @@ -93,11 +93,19 @@ export const _useResolveCall = <Result, Params extends ResolveCallParams>(
},
[call, paramsRef.current, validate],
);
const isEmpty = useMemo(() => {
if (data == null) {
return true;
}
if (Array.isArray(data) && data.length === 0) {
return true;
}
return false;
}, [data]);

const isLoading =
isFetching &&
data == null &&
(Array.isArray(data) ? data.length === 0 : true);
const isLoading = useMemo(() => {
return isFetching && isEmpty;
}, [isEmpty, isFetching]);

/**
* Automatically fetch the call function
Expand Down