Empty string array value not parsed correctly
soulprovidr opened this issue · comments
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= |
[] |
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
}