redux-query-sync icon indicating copy to clipboard operation
redux-query-sync copied to clipboard

Support for multiple (array) values

Open groupsky opened this issue 6 years ago • 2 comments

I have situation where a single query key is used multiple times to provide several values. The underlying URLSearchParams supports this case, but in getQueryValues the code uses only the first value.

I suggest to add a parameter option that specifies if the parameter is of array type and if so to use the URLSearchParams.getAll() for retrieving the values.

groupsky avatar Oct 18 '18 06:10 groupsky

Sounds fine to me.

I suppose that you'd want to specify something like multiple: true for a parameter, and then the value you get will always be an array. I wonder if, vice versa, you should then also always provide an array as the value. I think that would keep it simple and consistent.

As you say we'd have to run getAll() instead of get(), and probably delete() plus append() instead of set(), as I don't see a setAll() in the docs.

If you/anyone want to write and test this, feel free to open a PR.

Treora avatar Oct 18 '18 20:10 Treora

I actually did this recently. I also did multiple: true for the config, but I used a different approach to get and set the query params. I wasn't sure this was supported by URLSearchParams, so I achieved this with another package to parse the URLs. I'll check out the methods mentioned here first though.

timmysmalls avatar Dec 19 '19 07:12 timmysmalls