I want to pass a Date as a parameter to my backend using RTK Query. What is the best way to do that?
This is what it looks like today, and this does not work. I think it is because RTK doesn’t like non serializable objects, like dates.
export type ActionRequest ={
date: Date;
actionType: number;
}
Endpoint
const actionsApi = rootApi.injectEndpoints({
endpoints: (builder) => ({
fetchActions: builder.query<
Action[],
ActionRequest
>({
query: (req: ActionRequest) => ({
url: `/v1/action/list`,
method: 'GET',
params: req,
}),
...
This is what the request header look like using the code above:
http://localhost:1337/api/v1/action/list?date=Thu+May+02+2024+11%3A25%3A25+GMT%2B0200+%28Central+European+Summer+Time%29&actionType=1
Backend (C#) looks like this:
[HttpGet("list")]
public async Task<IReadOnlyList<ActionDto>> GetActions([FromQuery] DateTime date,
[FromQuery] int actionType,
)
{
...
}
How do I solve this in best way possible?