A Simple tRPC ExampleThis example with display the current time on the server and it will update every minute by re-calling the server.Loading...The client code uses the React 'useEffect' hook with a interval call to 'refetch' tRPC function:The server is setup as:It's probably overkill to call the server for the current time, but this is a nice simple demonstrates of how tRPC works. We have not included all the setup, some more boiler plate is not shown here.What is really interesting is that after the 'trpc', in this code, the types will auto complete to match those of the server (in this case 'greet' in the router definition code) as the developer types.As you can probably imagine, adding more server types and consuming them from the client after this setup would be straight forward and extremely efficient.
This example with display the current time on the server and it will update every minute by re-calling the server.The client code uses the React 'useEffect' hook with a interval call to 'refetch' tRPC function:The server is setup as:
Loading...
It's probably overkill to call the server for the current time, but this is a nice simple demonstrates of how tRPC works. We have not included all the setup, some more boiler plate is not shown here.
What is really interesting is that after the 'trpc', in this code, the types will auto complete to match those of the server (in this case 'greet' in the router definition code) as the developer types.
As you can probably imagine, adding more server types and consuming them from the client after this setup would be straight forward and extremely efficient.