2. Writing an RPC
Lesson 2: Writing an RPC
In the last lesson you called a server function. Now you'll write one.
live(fn) wraps any function as an RPC endpoint. The first argument is always ctx (the context), followed by whatever arguments the caller passes.
export const myFunc = live((ctx, arg1, arg2) => {
return arg1 + arg2;
}); The add function is already done. It takes two numbers and returns their sum.
Try it
- Create a
multiplyfunction that multiplies two numbers - Wrap it with
live()and export it - Import it in the component and add a button to test it
WebSocket
0
No messages yet