Kitchen Sink Example
preSearchFilters: [
// Persist (or set as default) the usersView search param
// while navigating within or to this route (or it's children!)
(search) => ({
...search,
usersView: {
...search.usersView,
},
}),
],
I know this is now deprecated in place of search middleware. However does this preSearchFilter actually do anything in the kitchen sink example? Nothing seems to change with this snippet removed9 Replies
continuing-cyanOP•11mo ago
from my understanding, wouldn't destructuring search and setting usersView to the destructured value of search.usersView be redundant?
flat-fuchsia•11mo ago
it depends
if you use a spread like this
<Link search={(p) => ({...p})>
it would have an effect
without the spread it does not work
which was one of the reasons we introduced search middlewares
do you have a particular use case in mind where you need support?continuing-cyanOP•11mo ago
honestly was just trying to get a better understanding of things. Was looking to contribute back to Tanstack so thought a good place to start would be documentation/examples until I had a fuller knowledge of the processes of tanstack router
flat-fuchsia•11mo ago
best thing for me usually is debugging an issue and stepping through the code and trying to understand what's going on 😆
continuing-cyanOP•11mo ago
ah i think i see the purpose of the search middleware in place of the presearch filters now.
so instead of previously having to set a Link like this
<Link
to="/dashboard/users/user"
search={(d) => ({
...d,
userId: user.id,
})}
className="block py-2 px-3 text-blue-700"
activeProps={{ className:
font-bold }}
>
with the current search params spread into the search prop
we can just create our Link with the new search params
<Link
to="/dashboard/users/user"
search={{
userId: user.id,
}}
className="block py-2 px-3 text-blue-700"
activeProps={{ className:
font-bold }}
>
and then use the middleware to retain our search params through the long method or the shorthand function
search: {
middlewares: [retainSearchParams(['usersView'])],
},
would that be correct implementation?flat-fuchsia•11mo ago
looks right yes
continuing-cyanOP•11mo ago
awesome thanks for all the help
flat-fuchsia•11mo ago
thanks for the example PR!
continuing-cyanOP•10mo ago
just saw this but no problem! If i come across anything else I'll be sure to send some more:)