Repository navigation
Feature-scoped typed query state factory #1349
Unanswered
damianricobelli
asked this question in
Ideas
Replies: 1 comment 3 replies
|
This looks similar to what @switz proposed in #446 (comment), and to what I'm working on (the "unified" API), ie wrapping all the APIs (hook, loader, serializer) into an object created from a description of the search params they will work with. I have a branch where I started implementing this, but there is one exported type that I'd have to change to make it work across all hooks. I'll have a look at your implementation to see if there is another way, to avoid a breaking change. I'll open an RFC discussion with those changes, pointing back to both of your implementations for comparison. |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I’d like to share a pattern we’re using with
nuqsand suggest it could be useful as a first-class API.Current situation (what we hit in real apps)
nuqsprimitives are excellent (useQueryState,useQueryStates, parser, etc), but in medium/large apps we usually add our own abstraction to get:useQueryState("view")) without repeating parser/key wiringurlKeyremappingWithout that, we tend to duplicate definitions in multiple places (param map + hook wrappers), or keep everything global and lose feature boundaries.
What feature/scope-based API could solve
A scoped factory can keep query state local to a feature while preserving full inference:
urlKey)Code
This is the code we currently have in my team for the abstraction
Example
Why this matters
For app features/scopes, this reduces boilerplate and keeps types aligned with behavior. In some app, what we could do is create different hooks for each route group. For example:
useCheckoutQueryStateonly allows us to access the search params of routes in the checkout route group.It also improves maintainability because query concerns are defined once and consumed consistently.
Question
Would it make sense for
nuqsto provide an official scoped typed factory (or an endorsed pattern in docs) for this use case?All reactions