Next.js Discord

Discord Forum

trpc + server actions

Unanswered
astro posted this in #help-forum
Open in Discord
i wanted to use trpc without react query like with next's server actions but using a relative url throws error
import React from "react";

export default function ProjectList() {
  async function getProjects() {
    const data = await fetch("/api/trpc/getProjects");
    return JSON.stringify(await data.json(), null, 2);
  }

  return <pre>{getProjects()}</pre>;
}

1 Reply

also whats the best way to setup trpc in next js without using react query(cuz i want to use server functions), currently im creating a server folder in src with index.ts and trpc.ts and inside /api i have /trpc/[trpc]/route.ts .