I have an issue when handling some parameters on a custom hook. I get the following TS error:
Property 'cardID' does not exist on type 'void'.
useCreateOrderItem.ts:
...
import { getTokenAuthHeaders } from '../../functions/sharedHeaders';
import { useMutation, useQueryClient } from 'react-query';
import { Types } from 'mongoose';
async function createOrderItem(cardID: Types.ObjectId, listID: Types.ObjectId, pageValue: number) {
const token = await getToken();
const response = await fetch(`${basePath}/lists/${listID}/order_item/`, {
method: 'POST',
body: JSON.stringify({ cardID, pageValue }),
headers: getTokenAuthHeaders(token)
});
return response.json();
}
export default function useCreateOrderItem() {
const { listID } = useParams();
const queryClient = useQueryClient();
return useMutation(
({ cardID, pageValue }) => { // Error appears here
if (listID != null) {
return createOrderItem(cardID, listID, pageValue);
}
},
{
onSuccess: () => {
return queryClient.invalidateQueries('list');
}
}
);
}
I call my hook over here:
...
import useCreateOrderItem from '../../hooks/Lists/useCreateOrderItem';
...
import { OrderItemType } from '../../types/OrderItemType';
export function OrderItem({ cardID, orderItem, listID }: { cardID: Types.ObjectId, orderItem: OrderItemType, listID: string }) {
const createOrderItemMutation = useCreateOrderItem();
...
const saveNewValue = async () => {
if (orderItem != null) {
...
} else {
await createOrderItemMutation.mutateAsync({
cardID,
pageValue
});
}
setValue([]);
setPageValueChanged(false);
};
}
I assume it has to do with the way I'm recieving my parameters on my useCreateOrderItem function, but I'm not quite sure if that's the case.