Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTK Query url with parameter which is an array #4678

Open
komarovalexander opened this issue Oct 28, 2024 · 2 comments
Open

RTK Query url with parameter which is an array #4678

komarovalexander opened this issue Oct 28, 2024 · 2 comments

Comments

@komarovalexander
Copy link

komarovalexander commented Oct 28, 2024

Hi team,
if I pass array (var array = ['v1', 'v2']) into params of rtk get query

query: (params) => ({
        url: `myurl`,
        method: "GET",
        params: { array: ['v1', 'v2'] },
      }),

it will send it in query this way: ?array=v1,v2,

but I need to send it as ?array[]=v1&array[]=v2

is there a plan to add array parse option?
to make it parse as ?array[]=v1&array[]=v2
thanks

@komarovalexander
Copy link
Author

I see somebody also faced with that https://stackoverflow.com/questions/73787483/rtk-query-url-with-parameter-which-is-an-array would be good to have a solution out-of-the-box, thanks

@EskiMojo14
Copy link
Collaborator

RTK Query already exposes the option to provide a custom paramsSerializer, which you can use to get the desired behaviour.

If one isn't provided, we just pass the object to URLSearchParams and let it do the parsing.

I don't think it makes sense for us to add our own support for this convention, since it's specific to a few APIs and there are already plenty of libraries you can use to do it (such as querystring like the SO comment you linked says)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants