use-location-state
use-location-state copied to clipboard
Ignore filter Default value
Is It possible to pass a parameter in the URL of some empty/null/undefined value so the default value will be ignored?
mhh can you give an example? what would be returned in that case?
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?
When you call setEmails([]) you will get the link you are looking for :)
#emails=%5B%C2%A0%5D
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
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?
It's react-router-dom useNavigate hook
did you try using a normal link <a href="..." />
?
Not yet, bet anyway it's not aligned with my code convention