-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
🐞 Bug Report
Describe the bug
IsLoading flag in pending state is false.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- use a useFetchye hook and defer it for later use
- In the useEffect run the returned fn from useFetchye to call the API - here loading flag is true
- Cancel the request using controller.abort
- re-run(call) the api again, this time isLoading flag is false when it should be true.
Additional info:
Create a simple component and use useFetchye with defer in that and try to use below code
const getData = (url, controller ) => async (fetchClient, requestPayload, options) => {
let payload;
let error;
try {
const res = await fetchClient(url, {
...options,
method: 'POST',
signal: controller.signal,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestPayload),
});
const {
data,
} = await res.json();
payload = {
data,
};
} catch (e) {
error = e;
}
return {
payload,
error,
};
};
useEffect(() => {
if (searchPayload) {
runAPI().then((response) => {
if (response?.error?.name === 'AbortError') {
return;
}
if (response.error || !blockResponse?.data?.data) {
// show error message
} else {
// logic here
}
});
}
return () => {
controller.abort();
};
}, [searchPayload]);
/// Dummy component code
const onSearch = () => {
setSearchPayload([{bid: 1212, isAvailable: true}])
}
const [searchPayload, setSearchPayload] = useState(null);
<button type="button" onClick={onSearch}></button>
Expected behavior
isLoadingFlag should be true everytime request is in pending state
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: [e.g. macOS, Windows]
- Browser (if applies) [e.g. chrome, safari]
- Version of fetchye: [e.g. 5.0.0]
- Node version:[e.g 10.15.1]
Additional context
Add any other context about the problem here.
Metadata
Metadata
Assignees
Labels
No labels