Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit b4e243e

Browse files
committed
chore: update examples to new api (#1021)
1 parent aea38ce commit b4e243e

File tree

5 files changed

+115
-116
lines changed

5 files changed

+115
-116
lines changed

examples/react/src/backend/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { registry } from "./registry";
2-
import { serve } from "@rivetkit/nodejs";
32

4-
serve(registry, {
3+
registry.runServer({
54
cors: {
65
// IMPORTANT: Configure origins in production
76
origin: "*",
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
// import { useState } from "react";
2-
// import { createClient, createRivetKit } from "@rivetkit/react";
3-
// import type { Registry } from "../backend/registry";
4-
//
5-
// const client = createClient<Registry>(`http://localhost:8080/registry`);
6-
// const { useActor } = createRivetKit(client);
7-
//
8-
// function App() {
9-
// const [count, setCount] = useState(0);
10-
// const [counterName, setCounterName] = useState("test-counter");
11-
//
12-
// const counter = useActor({
13-
// name: "counter",
14-
// key: [counterName],
15-
// });
16-
//
17-
// counter.useEvent("newCount", (x: number) => setCount(x));
18-
//
19-
// const increment = async () => {
20-
// await counter.connection?.increment(1);
21-
// };
22-
//
23-
// return (
24-
// <div>
25-
// <h1>Counter: {count}</h1>
26-
// <input
27-
// type="text"
28-
// value={counterName}
29-
// onChange={(e) => setCounterName(e.target.value)}
30-
// placeholder="Counter name"
31-
// />
32-
// <button onClick={increment}>Increment</button>
33-
// </div>
34-
// );
35-
// }
36-
//
37-
// export default App;
1+
import { useState } from "react";
2+
import { createClient, createRivetKit } from "@rivetkit/react";
3+
import type { registry } from "../backend/registry";
4+
5+
const client = createClient<typeof registry>(`http://localhost:8080/registry`);
6+
const { useActor } = createRivetKit(client);
7+
8+
function App() {
9+
const [count, setCount] = useState(0);
10+
const [counterName, setCounterName] = useState("test-counter");
11+
12+
const counter = useActor({
13+
name: "counter",
14+
key: [counterName],
15+
});
16+
17+
counter.useEvent("newCount", (x: number) => setCount(x));
18+
19+
const increment = async () => {
20+
await counter.connection?.increment(1);
21+
};
22+
23+
return (
24+
<div>
25+
<h1>Counter: {count}</h1>
26+
<input
27+
type="text"
28+
value={counterName}
29+
onChange={(e) => setCounterName(e.target.value)}
30+
placeholder="Counter name"
31+
/>
32+
<button onClick={increment}>Increment</button>
33+
</div>
34+
);
35+
}
36+
37+
export default App;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// import React from "react";
2-
// import ReactDOM from "react-dom/client";
3-
// import App from "./App";
4-
//
5-
// ReactDOM.createRoot(document.getElementById("root")!).render(
6-
// <React.StrictMode>
7-
// <App />
8-
// </React.StrictMode>,
9-
// );
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
import App from "./App";
4+
5+
ReactDOM.createRoot(document.getElementById("root")!).render(
6+
<React.StrictMode>
7+
<App />
8+
</React.StrictMode>,
9+
);

examples/trpc/scripts/client.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
// import { createTRPCClient, httpBatchLink } from "@trpc/client";
2-
// import type { AppRouter } from "../src/server.js";
3-
//
4-
// // Create tRPC client
5-
// const client = createTRPCClient<AppRouter>({
6-
// links: [
7-
// httpBatchLink({
8-
// url: "http://localhost:3001",
9-
// }),
10-
// ],
11-
// });
12-
//
13-
// async function main() {
14-
// console.log("🚀 tRPC Client Demo");
15-
//
16-
// try {
17-
// // Increment counter
18-
// console.log("Incrementing counter 'demo'...");
19-
// const result = await client.increment.mutate({ name: "demo" });
20-
// console.log("New count:", result);
21-
//
22-
// // Increment again
23-
// console.log("Incrementing counter 'demo' again...");
24-
// const result2 = await client.increment.mutate({ name: "demo" });
25-
// console.log("New count:", result2);
26-
//
27-
// console.log("✅ Demo completed!");
28-
// } catch (error) {
29-
// console.error("❌ Error:", error);
30-
// process.exit(1);
31-
// }
32-
// }
33-
//
34-
// main().catch(console.error);
1+
import { createTRPCClient, httpBatchLink } from "@trpc/client";
2+
import type { AppRouter } from "../src/server.js";
3+
4+
// Create tRPC client
5+
const client = createTRPCClient<AppRouter>({
6+
links: [
7+
httpBatchLink({
8+
url: "http://localhost:3001",
9+
}),
10+
],
11+
});
12+
13+
async function main() {
14+
console.log("🚀 tRPC Client Demo");
15+
16+
try {
17+
// Increment counter
18+
console.log("Incrementing counter 'demo'...");
19+
const result = await client.increment.mutate({ name: "demo" });
20+
console.log("New count:", result);
21+
22+
// Increment again
23+
console.log("Incrementing counter 'demo' again...");
24+
const result2 = await client.increment.mutate({ name: "demo" });
25+
console.log("New count:", result2);
26+
27+
console.log("✅ Demo completed!");
28+
} catch (error) {
29+
console.error("❌ Error:", error);
30+
process.exit(1);
31+
}
32+
}
33+
34+
main().catch(console.error);

examples/trpc/src/server.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
// import { registry } from "./registry.js";
2-
// import { initTRPC } from "@trpc/server";
3-
// import { createHTTPServer } from "@trpc/server/adapters/standalone";
4-
// import { z } from "zod";
5-
//
6-
// // Start RivetKit
7-
// const { client } = registry.run();
8-
//
9-
// // Initialize tRPC
10-
// const t = initTRPC.create();
11-
//
12-
// // Create tRPC router with RivetKit integration
13-
// const appRouter = t.router({
14-
// // Increment a named counter
15-
// increment: t.procedure
16-
// .input(z.object({ name: z.string() }))
17-
// .mutation(async ({ input }) => {
18-
// const counter = client.counter.getOrCreate(input.name);
19-
// const newCount = await counter.increment(1);
20-
// return newCount;
21-
// }),
22-
// });
23-
//
24-
// // Export type for client
25-
// export type AppRouter = typeof appRouter;
26-
//
27-
// // Create HTTP server
28-
// const server = createHTTPServer({
29-
// router: appRouter,
30-
// });
31-
//
32-
// server.listen(3001);
33-
//
34-
// console.log("tRPC server listening at http://localhost:3001");
1+
import { registry } from "./registry.js";
2+
import { initTRPC } from "@trpc/server";
3+
import { createHTTPServer } from "@trpc/server/adapters/standalone";
4+
import { z } from "zod";
5+
6+
// Start RivetKit
7+
const { client } = registry.createServer();
8+
9+
// Initialize tRPC
10+
const t = initTRPC.create();
11+
12+
// Create tRPC router with RivetKit integration
13+
const appRouter = t.router({
14+
// Increment a named counter
15+
increment: t.procedure
16+
.input(z.object({ name: z.string() }))
17+
.mutation(async ({ input }) => {
18+
const counter = client.counter.getOrCreate(input.name);
19+
const newCount = await counter.increment(1);
20+
return newCount;
21+
}),
22+
});
23+
24+
// Export type for client
25+
export type AppRouter = typeof appRouter;
26+
27+
// Create HTTP server
28+
const server = createHTTPServer({
29+
router: appRouter,
30+
});
31+
32+
server.listen(3001);
33+
34+
console.log("tRPC server listening at http://localhost:3001");

0 commit comments

Comments
 (0)