TanStackT
TanStack2y ago
11 replies
developed-pink

search params prev type not inferred

I tried to use the functional updater of the search prop as described here: https://tanstack.com/router/v1/docs/framework/react/guide/navigation#search-param-links

I implemented a simple counter (reproduction here: https://stackblitz.com/edit/tanstack-router-scf3nc?file=src%2Froutes%2Fabout.tsx,src%2Froutes%2Findex.tsx) and I noticed two things:

1) prev is inferred as:
(parameter) prev: {} | {
    count?: number | undefined;
}


the {} is really troublesome - in my editor, it leaves out the other part of the union completely because of it - and access to .count type errors with:

(parameter) prev: {} | {
    count?: number | undefined;
}


2) this is a runtime thing: If I set defaultPreloadStaleTime: 0 (as recommended for a react-query integration) and defaultPreload: 'intent' - the count updates in my component when I hover the link. Every time I hover it, the count increases :/
StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Everything is Relative

Believe it or not, every navigation within an app is relative, even if you aren't using explicit relative path syntax (../../somewhere). Any time a link is clicked or an imperative navigation call is made, you will always have an origin path and a destination path which means you are navigating from one route to another ...
Was this page helpful?