T
TanStack9mo ago
molecular-blue

Why Route.useSearch returns any here?

Hello, This is probably a stupid question, but I can't find my mistake. In this route:
import { createFileRoute } from "@tanstack/react-router";
import { z } from "zod";

export const Route = createFileRoute("/toto")({
validateSearch: () => ({
myparam: z.string().default("mydefaultvalue"),
}),
component: RouteComponent,
});

function RouteComponent() {
const data = Route.useSearch();
console.log(">>", data);
return <div>Hello "/toto"!</div>;
}
import { createFileRoute } from "@tanstack/react-router";
import { z } from "zod";

export const Route = createFileRoute("/toto")({
validateSearch: () => ({
myparam: z.string().default("mydefaultvalue"),
}),
component: RouteComponent,
});

function RouteComponent() {
const data = Route.useSearch();
console.log(">>", data);
return <div>Hello "/toto"!</div>;
}
data is of type any. What am I missing?
4 Replies
adverse-sapphire
adverse-sapphire9mo ago
your validator should be a z.object({ myparam: z.string().default("...")})
molecular-blue
molecular-blueOP9mo ago
hm what's the difference between @tanstack/router-zod-adapter and @tanstack/zod-adapter? I realised this example was wrong and I should have used your solution instead of a callback, but it didn't solve my issue
adverse-sapphire
adverse-sapphire9mo ago
we renamed to the one without the router prefix so use that
molecular-blue
molecular-blueOP9mo ago
ok thank you!

Did you find this page helpful?