In the React frontend in the CarList.tsx file, we have the following code
...
const { data, error, isSuccess } = useQuery({
queryKey: ["cars"],
queryFn: getCars
});
...
if (!isSuccess) {
return Loading...
}
else if (error) {
return Error when fetching cars...
}
else {
...
However, the else if (error) condition is unreachable, because the (!isSuccess) condition is always met first in the event of errors, effectively shadowing the error condition.
I suggest the following changes:
...
const { data, isSuccess, isError, isLoading } = useQuery({
queryKey: ["cars"],
queryFn: getCars
});
...
if (isLoading) {
return Loading...
}
else if (isError) {
return Error when fetching cars...
}
else if (isSuccess) {
...
In the React frontend in the CarList.tsx file, we have the following code ... const { data, error, isSuccess } = useQuery({ queryKey: ["cars"], queryFn: getCars }); ... if (!isSuccess) { return Loading... } else if (error) { return Error when fetching cars... } else { ...
However, the
else if (error)
condition is unreachable, because the (!isSuccess) condition is always met first in the event of errors, effectively shadowing the error condition.I suggest the following changes:
... const { data, isSuccess, isError, isLoading } = useQuery({ queryKey: ["cars"], queryFn: getCars }); ... if (isLoading) { return Loading... } else if (isError) { return Error when fetching cars... } else if (isSuccess) { ...