I would like to supply Dates as arguments to my RTK Queries. For instance, I have an interface like so that I supply to my queries:
export interface ScheduleIdentifier {
code: string;
date: Date;
}
I have endpoints like so that take a Date (via ScheduleIdentifier or the like):
export interface GetScheduleVariables {
schedule: ScheduleIdentifier;
}
export const MyApi = createApi({
reducerPath: 'myApi',
baseQuery: fetchBaseQuery({ baseUrl }),
endpoints: (builder) => ({
getSchedule: builder.query<GetSchedule, GetScheduleVariables>({
// attempt to make RTK Query happy about the date...
serializeQueryArgs: (params) => {
return JSON.stringify({
schedule: {
code: params.queryArgs.schedule.code,
date: params.queryArgs.schedule.date.toISOString()
}
});
},
query: (params) => ({
...
})
}),
})
});
Unfortunately - even despite the custom serializeQueryArgs function - I get a an error like so in the console:
A non-serializable value was detected in the state, in the path:
myApi.queries.{"schedule":{"code":"5ea5d2ec-59f6-4ed1-a9d2-fed92e532c73","date":"2023-07-27T00:00:00.000Z"},"filter":{}}.originalArgs.schedule.date
. Value: Date Wed Jul 26 2023 17:00:00 GMT-0700 (Pacific Daylight Time)Take a look at the reducer(s) handling this action type: myApi/executeQuery/pending.
EDIT: Adding Stack Trace
index.js:1191
e index.js:1191
Redux 19
React 3
query index.tsx:148
ScheduleViewPage index.tsx:223
React 5
unstable_runWithPriority scheduler.development.js:401
React 4
unstable_runWithPriority scheduler.development.js:401
React 6
render index.tsx:34
tsx index.tsx:36
tsx main.chunk.js:144741
Webpack 7
I've googled around, but I haven't been able to find a clear answer on how to approach this. Please advise - thank you!