#React query seems to be corruption date fields.

2 messages · Page 1 of 1 (latest)

bitter cedar
#

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;
    },
runic pollen
#

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)