Skip to content

useQueryParams: Serialize arrays using brackets and improve typing

Pandu Supriyono requested to merge feature/use-query-param-options into master

Background

This MR has addresses two things:

  • In Drupal, queries may expect arrays using bracket notation (c.q. ?foo[]=bar&foo[]=baz&foo[]=qux. When using the queryParams variable to build an URL that bears a search query, array parameters with only one value were cast as strings (i.e. ?foo=bar instead of ?foo[]=bar. This caused bad request errors since Drupal would not expect a string, but an array.
  • In TypeScript projects, it was difficult to work with the existing typings since we used the object type, which refers to a Reference Type that may not have a key-value structure. As such, we encountered compilation errors during building.

What's changed

  • Ensured that query parameters that receive array values are always serialised using bracket notation (see above)
  • Made the JSDoc typings more accurate, which improves TypeScript interop
Edited by Pandu Supriyono

Merge request reports

Loading