T
TanStack3y ago
broad-brown

How to type a response from Next.js NextResponse.json() using useQuery and Supabase

I'm using React Query to call a route handler in Next.js, I return a response from Supabase like so:
// Route handler
export async function GET() {
...
return NextResponse.json({ success: true, data });
}

// Another separate file
const { data, isLoading, isError, error } = useQuery({
queryKey: ["photos"],
queryFn: () => axios.get("/api/photos"),
});
// Route handler
export async function GET() {
...
return NextResponse.json({ success: true, data });
}

// Another separate file
const { data, isLoading, isError, error } = useQuery({
queryKey: ["photos"],
queryFn: () => axios.get("/api/photos"),
});
Now the problem comes when I try to access data, I basically get data.data.data and that's where my array of objects is, how can I simplify this type/structure so I don't drill data 3 times?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?