This example showcases the use of httpSubscriptionLink
to facilitate .useSubscription
via Server-sent Events.
Try demo http://sse.trpc.io/
- 🧙♂️ E2E type safety with tRPC
- ⚡ Full-stack React with Next.js
- ⚡ Server-Sent-Events / Subscription support
- ⚡ Database with Drizzle
- 🔐 Authorization using next-auth
This project includes 2 examples of the subscription pattern:
- Simple example of
whoIsTyping
- A slightly more involved example of
livePosts
- Hooks for both cases (using
trpc.{x}.useSubscription
) can be found in/src/app/channels/[channelId]/hooks.ts
- The
EventEmitter
&whoIsTyping
subscription route can be found in/src/server/routers/channel.ts
- The more complex
post
subscription route can be found in/src/server/routers/post.ts
git clone [email protected]:trpc/examples-next-sse-chat.git
pnpm i
cp .env.example .env
pnpm dev