use-location-state icon indicating copy to clipboard operation
use-location-state copied to clipboard

Ignore filter Default value

Open ariel-upstream opened this issue 1 year ago • 8 comments

Is It possible to pass a parameter in the URL of some empty/null/undefined value so the default value will be ignored?

ariel-upstream avatar May 15 '23 07:05 ariel-upstream

mhh can you give an example? what would be returned in that case?

xiel avatar May 15 '23 10:05 xiel

For example: In Home page: const [emails, setEmails] = useQueryState<string[]>("emails", ["[email protected]"]) now I want to navigate from another page to my Home page but without the default email filter I will try something like: navigate("home#emails: []") but I will get the filter with the "[email protected]" value Is it possible to pass some value(e.g.: null, explicit empty array) that will ignore the default filter value?

ariel-upstream avatar May 15 '23 12:05 ariel-upstream

When you call setEmails([]) you will get the link you are looking for :)

#emails=%5B%C2%A0%5D

xiel avatar May 15 '23 14:05 xiel

I don't have access to setEmails from another page, can I do it from the URL? I tried: navigate({ pathname: "/home", hash: createSearchParams({ emails: [], }).toString() }) also tried: navigate("/home#emails=%5B%C2%A0%5D")

and I still get the default filter in the state of emails

ariel-upstream avatar May 15 '23 14:05 ariel-upstream

Can u please try to navigate using a normal anchor? (to href= home#emails=%5B%C2%A0%5D)

Maybe the hash update does not correct coming from this navigate fn? where does it come from?

xiel avatar May 15 '23 16:05 xiel

It's react-router-dom useNavigate hook

ariel-upstream avatar May 16 '23 06:05 ariel-upstream

did you try using a normal link <a href="..." />?

xiel avatar May 16 '23 08:05 xiel

Not yet, bet anyway it's not aligned with my code convention

ariel-upstream avatar May 16 '23 12:05 ariel-upstream