Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

feat: Add "clear on default" option #493

Merged
merged 4 commits into from
Feb 11, 2024
Merged

feat: Add "clear on default" option #493

merged 4 commits into from
Feb 11, 2024

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Feb 10, 2024

Adds an option to remove the key-value pair when setting a state to the default value. Default behaviour remains to keep it explicitly set in the URL, for backwards-compatibility when defaults change.

Closes #320.
Closes #488.
Closes #490.

Copy link

vercel bot commented Feb 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2024 10:19am

Copy link

@zbeyens zbeyens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Member Author

@franky47 franky47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the naming of the option itself (which is hard to convey while keeping it short), one nitpick I may have with this implementation is that it's possible to specify clearOnDefault while not having set a default value, for which it will not do anything.

useQueryState('foo', parseAsInt.withOptions({
  clearOnDefault: true
})

But then again, the intent is clear, and the alternative would require a large refactor of the type system. This will probably happen in v2.

@franky47 franky47 merged commit df5e894 into next Feb 11, 2024
15 checks passed
@franky47 franky47 deleted the feat/clear-on-default branch February 11, 2024 12:30
Copy link

🎉 This PR is included in version 1.17.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@rwieruch
Copy link

rwieruch commented Feb 19, 2024

Good addition to the package! FYI use-query-params which I always used for SPAs and Next Page Router has this option as well. There it's called removeDefaultsFromUrl.

@franky47
Copy link
Member Author

@rwieruch good catch, thanks! I'll update the docs to make the connection (since it's been released into stable, it's a bit late to change the name).

@franky47 franky47 mentioned this pull request Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants