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

Empty string array value not parsed correctly #274

Open
soulprovidr opened this issue Aug 18, 2023 · 1 comment
Open

Empty string array value not parsed correctly #274

soulprovidr opened this issue Aug 18, 2023 · 1 comment

Comments

@soulprovidr
Copy link

Hi – first of all, thanks for your work on this library.

I ran into what I believe is a bug today and would like to understand if there is any way to work around it.

Given the following param definition:

const [urlParams, setUrlParams] = useQueryParams({
    foo: ArrayParam,
  });

Expected behaviour:

URL params foo value
?foo=bar&foo= ['bar', '']
?foo= ['']

Actual behaviour:

URL params foo value
?foo=bar&foo= ['bar', '']
?foo= []
@soulprovidr
Copy link
Author

soulprovidr commented Aug 18, 2023

It seems like the getEncodedValueArray function could be modified, although I might be blind to potential side effects:

function getEncodedValueArray(
  input: string | (string | null)[] | null | undefined
): (string | null)[] | null | undefined {
  if (input == null) {
    return input;
  }

  return input instanceof Array ? input : input === '' ? [''] : [input];  // Empty string no longer returns empty array
}

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

1 participant