Alan_sztA
tRPC2y ago
2 replies
Alan_szt

How to get access to the types generated by the server in the frontend (React)?

In this example, how do you replace data: any to the correct type?

import { trpc } from "../utils/trpc";

type Props = {
  onSuccess: (data: any) => void;
};
export function CreateWorker(props: Props) {
  const createWorkerMutation = trpc.createWorker.useMutation();

  const handleCreateWorker = () => {
    createWorkerMutation.mutate(
      { data: "hello" },
      {
        onSuccess: (data) => props.onSuccess(data),
      }
    );
  };
  return <button onClick={handleCreateWorker}>create</button>;
}
Was this page helpful?