Name | Progress |
---|---|
Introduction | Not Read |
๐ฐ Player | Not Read |
Name | Progress |
---|---|
Software Installation | Not Read |
Project Setup | Not Read |
Running and Testing | Not Read |
React and ReactDOM | Not Read |
๐ก Assignment 1: Welcome Message | Not Attempted |
Submissions | Not Read |
Name | Progress |
---|---|
JSX and Components | Not Read |
Props | Not Read |
๐พ Exercise: Props | Not Attempted |
CSS Styles | Not Read |
useState and Hooks | Not Read |
๐พ Exercise: useState | Not Attempted |
Conditional Rendering | Not Read |
Lists | Not Read |
๐พ Exercise: Lists | Not Attempted |
Forms and Events | Not Read |
๐พ Exercise: Forms | Not Attempted |
๐ก Assignment 2: Front End | Not Attempted |
Name | Progress |
---|---|
Pure Components - memo | Not Read |
Lifecycle - useEffect | Not Read |
Expensive? - useMemo | Not Read |
DOM Interactions - useRef | Not Read |
forwardRef | Not Read |
useImperativeHandle | Not Read |
๐พ useImperativeHandle | Not Attempted |
Context | Not Read |
useCallback | Not Read |
useId | Not Read |
useReducer | Not Read |
Name | Progress |
---|---|
Database | Not Read |
NextAuth and Github Authentication | Not Read |
Prisma and ORM | Not Read |
Project Setup | Not Read |
Project Authentication | Not Read |
Name | Progress |
---|---|
APIs | Not Read |
APIs - Slides | Not Attempted |
Rest APIs | Not Read |
Rest APIs - Express.js | Not Read |
ReastAPIs - Next.js | Not Read |
Securing APIs | Not Read |
Securing APIs - NextAuth | Not Read |
It is time to add tRPC to your project and show you how easy it is to call tRPC methods both from the client and server. Your project comes pre-configured for tRPC as part of the T3 Stack. This configuration comes with automated handling of authorisations giving you one less thing to worry about.
To add a new API route handler, we need to define a new router. Please create the following router file in src/server/api/routers/tasks.ts
import { z } from "zod";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
const tasks = [
{
userId: "1",
id: 1,
description: "Complete the project report",
completed: false
},
{ userId: "1", id: 2, description: "Clean the house", completed: true }
];
export const tasksRouter = createTRPCRouter({
tasks: protectedProcedure.query(async ({ ctx }) => {
return tasks.filter((task) => task.userId === ctx.session.user.id);
}),
createTask: protectedProcedure
.input(z.object({ message: z.string() }))
.mutation(async ({ ctx, input }) => {
// TODO
}),
});
There are a few things to observe here:
We have only defined the router handlers for the tasks router. We still need to register as part of the tRPC router. Therefore, in the src/server/api/root.ts please add modify the router definition to include the following:
import { tasksRouter } from "./routers/tasks";
export const appRouter = createTRPCRouter({
tasks: tasksRouter
});
Please implement the rest of the handlers for createTask, updateTask and deleteTask.