tRPCttRPC
Powered by
Liltripple_reidL
tRPC•3y ago•
11 replies
Liltripple_reid

useMutation throwing 500 errors

I've setup my next 13 app router project and started using some queries that worked fine, however the only route I have for mutations fails without any detailed error. I'm using the
createTRPCReact
createTRPCReact
with a custom client for RSC.

"use client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { useState, type ReactNode } from "react";
import superjson from "superjson";
import { apiRSC } from "~/utils/api";

/**
 *
 * @description should be updated when trpc releases an RSC and Edge compatible version
 *
 */
export const TRPCProvider = ({ children }: { children: ReactNode }) => {
  const [queryClient] = useState(() => new QueryClient());
  const [trpcClient] = useState(() =>
    apiRSC.createClient({
      links: [
        httpBatchLink({
          url: "http://localhost:3000/api/trpc",
        }),
      ],
      transformer: superjson,
    })
  );

  return (
    <apiRSC.Provider client={trpcClient} queryClient={queryClient}>
      <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
    </apiRSC.Provider>
  );
};
"use client";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { httpBatchLink } from "@trpc/client";
import { useState, type ReactNode } from "react";
import superjson from "superjson";
import { apiRSC } from "~/utils/api";

/**
 *
 * @description should be updated when trpc releases an RSC and Edge compatible version
 *
 */
export const TRPCProvider = ({ children }: { children: ReactNode }) => {
  const [queryClient] = useState(() => new QueryClient());
  const [trpcClient] = useState(() =>
    apiRSC.createClient({
      links: [
        httpBatchLink({
          url: "http://localhost:3000/api/trpc",
        }),
      ],
      transformer: superjson,
    })
  );

  return (
    <apiRSC.Provider client={trpcClient} queryClient={queryClient}>
      <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
    </apiRSC.Provider>
  );
};


my trpc-client creator
export const apiRSC = createTRPCReact<AppRouter>();
export const apiRSC = createTRPCReact<AppRouter>();
Screenshot_2023-09-03_at_22.32.03.png
Screenshot_2023-09-03_at_22.32.28.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

throwing custom errors from mutations
asheeshhAasheeshh / ❓-help
3y ago
Throwing fastify errors when using fastify adapter
rdRrd / ❓-help
3y ago
useMutation called twice
Answer OverflowAAnswer Overflow / ❓-help
2y ago