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

Transform useQueryParams keys + omit empty ArrayParams #214

Open
nwbhatia opened this issue Apr 15, 2022 · 0 comments
Open

Transform useQueryParams keys + omit empty ArrayParams #214

nwbhatia opened this issue Apr 15, 2022 · 0 comments

Comments

@nwbhatia
Copy link

nwbhatia commented Apr 15, 2022

Hi, can someone help me understand if it's possible to do the following two things?

My current implementation is as follows:

  const [tags, setTags] = useQueryParams({
    0: withDefault(ArrayParam, []),
    1: withDefault(ArrayParam, []),
    2: withDefault(ArrayParam, []),
    3: withDefault(ArrayParam, []),
    4: withDefault(ArrayParam, []),
  });

Now, given an example, this encodes to:

?0=tagA&1=&2=tagB_tagC&3=&4=

However, say instead I would like to encode this object as:

?zero=tagA&two=tagB_tagC

Thus the two things I'm trying to do are:

  1. Apply a transformation to the key in the useQueryParams object upon encoding (0 -> "zero").
  2. Omit empty array params from the encoded string result.

without modifying the actual state definition (as I need numerical object keys and the empty lists for other implementation reasons).

Assuming this is possible, would really appreciate any advice or examples! 😃

@nwbhatia nwbhatia changed the title How to apply transformation to useQueryParams keys and omit empty ArrayParams upon encoding? Transform useQueryParams keys + omit empty ArrayParams upon encoding? Apr 22, 2022
@nwbhatia nwbhatia changed the title Transform useQueryParams keys + omit empty ArrayParams upon encoding? Transform useQueryParams keys + omit empty ArrayParams Apr 22, 2022
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