8 Replies
like-gold
like-gold2y ago
I personally would try to use either from if I'd just want to update search or params on the current route and be type safe or I'd use to if I want navigate elsewhere. I find not specifying from and to very odd because we cannot guarantee any type safety with params and search
quickest-silver
quickest-silverOP2y ago
So do you agree that to should be mandatory?
like-gold
like-gold2y ago
Short answer is I do but not sure if our users do. As mentioned I would avoid not having to or from. TS can't help you there @Manuel Schiller
harsh-harlequin
harsh-harlequin2y ago
Just weighing in here, I'd say navigation should probably require the user either pass in from or to. Never should they both be able to be undefined.
like-gold
like-gold2y ago
From a TS performance point of view, it is quite hard to optimise the cases where these two are not set. The params/search become a union of all possible search and params. For large code bases, this union could be massive. But generally as a user I'd always want to narrow this down to be more useful anyway imo
quickest-silver
quickest-silverOP2y ago
What's the use-case for using navigate to the same url? Is it updating search params? If so I think this could be bettet abstracted with its own util like setSearch Oh wait, but we'd want a navigation with a Link. Nevermind 🤦‍♂️
multiple-amethyst
multiple-amethyst2y ago
while I also think that one should specify ideally both to and from, I think it is okay that both are optional. Specifying them let's the user to opt-in into more typesafety, since if both to and from are missing: typeof params is the union of all path params typeof search is the union of all search params we previously discussed offering specialized APIs for e.g. updating search, but this was postponed until later when the use cases are clear, runtime is stable etc. we didn't want to widen the API surface just yet
like-gold
like-gold2y ago
I would generally encourage someone to use from/to here though. I'm not sure if the current API might lead to sloppiness because it will work without from/to I'd personally prefer to explicitly opt out of type safety rather than explicitly opt in But I'm a type safety nut so someone might disagree

Did you find this page helpful?