When attempting to alter the backend response using the transformResponse function, I encountered an error even when simply returning the "baseQueryReturnValue" argument.
export const categoryApiSlice = createApi({
reducerPath: "Categories",
baseQuery: fakeBaseQuery(),
tagTypes: ["CategoriesTag"],
endpoints: (builder) => ({
getAllCategories: builder.query<Category[], void>({
async queryFn() {
try {
const ref = collection(db, "categories");
const querySnapshot = await getDocs(ref);
let categories: Category[] = [];
querySnapshot?.forEach((doc) => {
categories.push({ id: doc.id, ...doc.data() } as Category);
});
return { data: categories };
} catch (error: any) {
console.error(error.message);
return { error: error.message };
}
},
transformResponse(baseQueryReturnValue, meta, arg) {
return baseQueryReturnValue
},
providesTags: ["CategoriesTag"],
}),
}),
});
export const { useGetAllCategoriesQuery } = categoryApiSlice;
An error occurred with the following message:
Type '(baseQueryReturnValue: unknown, meta: {}, arg: void) => unknown' is not assignable to type '(baseQueryReturnValue: unknown, meta: {}, arg: void) => Category[] | Promise
I also attempted to modify the response within the queryFn instead of using transformResponse, but was unsuccessful in doing so.