Allow custom search param parser to be passed to "useSearch" #553
briavicenti
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I currently am passing a numerical ID string as a search param, which then gets parsed as a number with the default
parseSearch
behavior:As you can imagine, this doesn't work for 0-prefixed ids such as the one above, because they are set to the equivalent numerical primitive (
0000
-->0
,0012
-->12
, etc).To get around this, I've implemented the following
parseSearch
method that usesURLSearchParams
to parse all param values as strings:However, the fact that this parsing behavior is app-wide will make it onerous to parse actual numerical or boolean primitives on other screens where we are using search params. I've also yet to figure out a way to override the React Location types such that
MakeGenerics
does not accept an object with non-string values, meaning that devs in my repo may type a param as anumber
but actually receive astring
instead if they don't notice this top-level parsing override.I would love to implement a custom parser only for this sole case where we are sure we need one. Would it be possible to add a param for the
useSearch
hook for a custom parser that overrides the top-level default?Beta Was this translation helpful? Give feedback.
All reactions