T
TanStack4y ago
like-gold

React query seems to be corruption date fields.

Hi there. I'm using a mutation in order to do a post call with axios. Right now data contains a field data.trackDays which is an array and each trackDay has a trackDayDate field. If I console.log that right before const response = axios.... then will the value of that field be "2022-09-29T22:00:00.000Z". But if I use the browsers network inspection tool to look at the post request can I see the value now is set to trackDayDate: "2022-09-28T22:00:00.000Z" ?! Anybody who have a clue what could be causing this?
export const useCreateCarQuote = (
nextStep: string,
locale?: string,
initial?: boolean
) => {
const queryClient = useQueryClient();

const [auth] = useRecoilState(authorizationState);
const [carFormState, setCarFormState] = useRecoilState(CarFormState);

return useMutation(
async (data: any) => {
const response = axios.post<CarQuote>(
`${process.env.GATSBY_API_URL}/trackday/quote`,
{ ...data },
{
headers: {
"Content-Type": "application/json"
},
}
);
return await response;
},
export const useCreateCarQuote = (
nextStep: string,
locale?: string,
initial?: boolean
) => {
const queryClient = useQueryClient();

const [auth] = useRecoilState(authorizationState);
const [carFormState, setCarFormState] = useRecoilState(CarFormState);

return useMutation(
async (data: any) => {
const response = axios.post<CarQuote>(
`${process.env.GATSBY_API_URL}/trackday/quote`,
{ ...data },
{
headers: {
"Content-Type": "application/json"
},
}
);
return await response;
},
2 Replies
sunny-green
sunny-green4y ago
I don't think this is a React Query thing. I don't totally understand the problem--the two string you provided are exactly the same--but I would guess this is something that could be alleviated with TypeScript instead of using data: any. I'd guess the types you're expecting are different than what you're actually working with, whether it's the response you're getting or the data you're sending along in the request. Also I'd avoid doing { ...data } whenever possible. It can just be passed in directly. axios.post('/trackday/quote', data)
like-gold
like-goldOP4y ago
My bad that was a mistake! the string I'm passing to the hook in the data component is "2022-09-29T22:00:00.000Z" and the one I can see when I inspect the request is always onde day behind so it will be "2022-09-28T22:00:00.000Z" in this case.

Did you find this page helpful?