feat: defaultOptions for NuqsAdapter#1066
Conversation
|
@TkDodo is attempting to deploy a commit to the 47ng Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
commit: |
franky47
left a comment
There was a problem hiding this comment.
Thanks, it looks good, I'd be more generic about the AdapterDefaultOptions type to allow extending it in the future with other props passed via the adapter (like a callback function to process URLSearchParams after applying updates for alphabetical sorting).
I don't think it's an issue, but could passing an object from the render body cause re-renders? I guess as long as the parent component of <NuqsAdapter> isn't re-rendered it shouldn't be an issue, and that would cause the whole app to re-render anyway (as adapters are placed high in the tree).
function RootLayout({ children }) {
return (
<NuqsAdapter defaultOptions={{ shallow: false })>
{children}
</NuqsAdapter>
)
}| import type { AdapterInterface, UseAdapterHook } from './defs' | ||
|
|
||
| export type AdapterContext = { | ||
| export type AdapterDefaultOptions = { |
There was a problem hiding this comment.
nitpick: There are other things we could pass through that Context from adapter props, so this type could be more generically named AdapterProps, what do you think?
There was a problem hiding this comment.
yeah that makes a lot of sense. AdapterDefaultOptions is actually the defaultOptions object inside the AdapterProps 👍
|
@franky47 regarding re-renders: currently, the context so that alone could cause re-renders. However, that’s only a concern IF the If there’s a top-down render, |
|
🎉 This PR is included in version 2.5.0-beta.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 2.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Is this feature planned? We're definitely looking for this feature specifically. (alphabetical sorting of parameters) |
|
@Multiply would you like to try your hand at a PR? |
Was already looking into the recent introduction of global default config. |
|
Let's continue the discussion in #1109. |
This PR adds
defaultOptionsto<NuqsAdapter>, which allows to override the globally specified defaults.As a first step, only
shallow?: booleancan be provided, but it can be extended to more default values.